Skip to content
Discussion options

You must be logged in to vote

A couple of options here:

  1. Use cast (type-only, no runtime check)
from typing import cast

var: str = cast(str, Variable.get("my_variable"))
  1. Force it to be a string at runtime
var = str(Variable.get("my_variable"))
  1. Tell Prefect you expect a string (and explicitly validate at runtime that it is one)
v = Variable.get("my_variable")
if not isinstance(v, str):
    raise TypeError(f"Expected str for my_variable, got {type(v).__name__}")
var: str = v

Replies: 3 comments 7 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@bdalpe
Comment options

@sghegoiu-rokos
Comment options

Comment options

You must be logged in to vote
5 replies
@sghegoiu-rokos
Comment options

@zzstoatzz
Comment options

@sghegoiu-rokos
Comment options

@bdalpe
Comment options

@zzstoatzz
Comment options

Answer selected by sghegoiu-rokos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants