Skip to content

Strange behavior when one of the constraints of a generic class's type variable is typing.Any? #9744

Closed Answered by erictraut
A-Paint-Brush asked this question in Q&A
Discussion options

You must be logged in to vote

In this code sample, you're using a value-constrained type variable. The behaviors of value-constrained type variables are woefully underspecified in the Python typing spec. I generally recommend against using them if at all possible. They are not found in any other language or type system — and for good reason. It's unfortunate that they were added to the Python type system, and it's not clear whether we'll ever be able to fully specify them in a way that composes well with other type features.

One aspect of value-constrained type variables that is unspecified is what a type checker should do when two or more of the constraint types are overlapping. In your example, all three constraint …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@A-Paint-Brush
Comment options

Answer selected by A-Paint-Brush
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