cnsmyth
09/17/2024, 12:51 AM@task
in front of a class function where self
is a parameter throws off the parameter passing? As in..
class MyClass:
def __init__():
pass
@task
def my_func(self, arg1, arg2):
pass
class_obj = MyClass()
class_obj('arg1', 'arg2')
Will throw an error where my_func is expecting arg2?Girish Sarwal
09/17/2024, 6:46 AM<http://myclass.my|myclass.my>_func()
in the body, the other way could be to ditch classes and use functional code?cnsmyth
09/17/2024, 3:38 PMNate
09/18/2024, 3:31 PMIn [1]: from prefect import task
In [2]: class MyClass:
...: def __init__(self): pass
...: @task
...: def f(self, x, y):
...: print(self, x, y)
...:
In [3]: obj = MyClass()
In [4]: obj.f(42, 9001)
10:30:29.413 | INFO | Task run 'f' - Created task run 'f' for task 'f'
<__main__.MyClass object at 0x1160c4f20> 42 9001
10:30:29.423 | INFO | Task run 'f' - Finished in state Completed()
In [5]: !prefect version
Version: 3.0.2+19.ga2dd7af098.dirty
API version: 0.8.4
Python version: 3.12.5
Git commit: a2dd7af0
Built: Tue, Sep 17, 2024 9:37 PM
OS/Arch: darwin/arm64
Profile: pong
Server type: cloud
Pydantic version: 2.9.2
Nate
09/18/2024, 3:32 PMditch classes and use functional code?this used to be our suggestion and honestly it's not a bad way to go IMO but we decided to explicitly support instance methods now, so it should work
Girish Sarwal
09/19/2024, 1:16 PM