Hello :wave: I would love to use Parameter and my...
# prefect-server
a
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
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
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
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
🚀 1