Skip to content

typing.cast() is ignored #1885

Answered by brianschubert
multani asked this question in Q&A
Discussion options

You must be logged in to vote

Hi! This is expected. cast only changes the type of an expression. It doesn't change the type of variables or otherwise propagate typing assumptions to parts of the program outside of the expression it's used on.

For example, valid (albeit dubious) uses of cast might look like

a = typing.cast(str, 1)
a += "foo"
# or
a = 1
a += typing.cast(int, "foo")

Could you elaborate a bit on what you're trying to achieve? There might be a different typing construct better suited for the task than typing.cast.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@multani
Comment options

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