Narrowing Variable Types #19746
-
|
Hi, Was wondering what the suggested method is for narrowing a variable type when getting it with Is it possible to tell the type checker that the value of |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 7 replies
-
|
Hi @sghegoiu-rokos, Yes, you can include a type hint as part of your code. This allows your IDE or type checker to statically validate the type. from prefect import flow
from prefect.variables import Variable
@flow
def my_flow():
var: str = Variable.get("my_variable") # note the addition of `: str` type hint after the variable name here
# ... rest of the flow logic ...NB: This type hint is not enforced at runtime. If you need runtime type enforcement, you'll need to use |
Beta Was this translation helpful? Give feedback.
-
|
thanks for the answer @bdalpe, unfortunately that doesnt seem to work for me
|
Beta Was this translation helpful? Give feedback.
-
|
A couple of options here:
|
Beta Was this translation helpful? Give feedback.


A couple of options here:
cast(type-only, no runtime check)