Skip to content

Why pyright can't correctly infer the return type of overload here #9258

Answered by erictraut
maple3142 asked this question in Q&A
Discussion options

You must be logged in to vote

You're attempting to use a value-constrained type variable here. And you're constraining it to literal values, no less. I recommend against using value-constrained type variables in your code. Their behaviors are not well defined in the typing spec, and you will see different assumptions and behaviors across type checkers. Value-constrained type variables are unique to the Python type system. You won't find them in any other type system for good reason.

I recommend switching away from value-constrained type variables. An overload is the appropriate and recommended approach in this case.

Replies: 1 comment 1 reply

Comment options

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

Answer selected by maple3142
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