Hello 👋
I would love to use Parameter and mypy together. However currently when I do;
Copy code
var: str = Parameter('var')
mypy complains with
Copy code
Incompatible types in assignment (expression has type "Parameter", variable has type "str")
Even though after calling this will be a string 🤔
Any thoughts on how to achieve this?
b
Bouke Krom
09/02/2021, 11:53 AM
If you do this in a
with Flow(name) as flow:
context, the returned value will actually not be a string but a task... We didnt implement type checking on tasks/parameters though, so I'm not sure how to solve it.
z
Zach Angell
09/02/2021, 1:50 PM
Hi @Alexander van Eck, this can be tricky. Because of deferred execution of course mypy is correct,
var
IS a
Parameter
until it's evaluated at flow run time.
A couple possibilities I can think of
1. use a union of types
var: Union[str, Parameter] = Parameter('var')
2. tell mypy to ignore it
var: str = Parameter('var') # type: ignore
We're working on some features that will allow Parameter typing (and enforcement of typing!!) in the future.
a
Alexander van Eck
09/02/2021, 1:51 PM
Great to hear @Zach Angell 🙂 I’ve gone with
cast
where necessary. but it looks like when passing Parameter into a prefect task it actually doesn’t complain! Just when using Parameter directly
Bring your towel and join one of the fastest growing data communities. Welcome to our second-generation open source orchestration platform, a completely rethought approach to dataflow automation.