Skip to content
Discussion options

You must be logged in to vote

The value expression str | int at runtime produces an object that is an instance of UnionType. It is not an instance of the type class, so it's not assignable to type. The typing spec is clear on that point, so pyright is correct in flagging that as a type violation.

Pyright should reject both of the above cases. The fact that it doesn't in the second case (involving an overload) is a bug.

It looks like you are using str | int as a type form — that is, you want it to be interpreted as a type expression rather than a value expression. There is a draft PEP 747 that introduces a mechanism in the type system to handle type forms.

Replies: 2 comments 2 replies

Comment options

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

Answer selected by inaku-Gyan
Comment options

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

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