Danny Vilela
02/04/2021, 11:21 PMfrom prefect import Flow
from prefect import Task
class AddTask(Task):
def run(self, x: int, y: int) -> int:
return x + y
with Flow(name="adding") as flow:
adder: AddTask = AddTask()
a: int = adder(x=1, y=2)
b: int = adder(x=a, y=3)
print(a, b)
flow.run()
It runs just fine, but I get two different “warning” highlights from my IDE (PyCharm):
1. On the def run(self, x: int, y: int) -> int
line: Signature of method 'AddTask.run()' does not match signature of base method in class 'Task'
2. On both assignment lines in the flow: Expected type 'int', got 'AddTask' instead
I’d like to know what I’m doing that’s un-Prefect-like. Does Prefect work well with type annotations? I’m aware that, really, the x
and y
parameters to AddTask
are actually converted to parameters (or a constant task?). But that’s maybe not as clear as annotating them as integers.Zanie
Danny Vilela
02/04/2021, 11:32 PMrun
method? It’s no real problem to silence mypy/the IDE on those lines (e.g., # noqa
), but just making sure 🙂Zanie
Danny Vilela
02/04/2021, 11:35 PMSignature of method 'AddTask.run()' does not match signature of base method in class 'Task'
. For the second point you can just set b: int = adder(x=a, y=2) # noqa
. For the first, you’d have to do def run(self, x: int, y: int) -> int: # noqa
. Just checking that my understanding of how/when you need to silence the type checker is correct!Zanie
def run(self) -> None:
you'll get a mismatch error there. I'm not sure why we don't have it take Any
and return Any
but even then I think that pycharm may complain.Danny Vilela
02/04/2021, 11:40 PMZanie