You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Unfortunately, mypy complains: error: TypeVar default must be one of the constraint types [misc]. While this is of course generally sound advice, a default of Any should always be permissible, as this allows memoryview to stand for any possible memoryview type. Without it, users are forced to write memoryview[Any] in every instance, which is unreasonable.
I agree with your position, yet the spec seems to disallow that:
For constrained TypeVars, the default needs to be one of the constraints. A type checker should generate an error even if it is a subtype of one of the constraints.
Activity
sterliakov commentedon Nov 7, 2025
I agree with your position, yet the spec seems to disallow that:
srittau commentedon Nov 10, 2025
Thanks, for pointing this out. I've opened a discussion at https://discuss.python.org/t/constrained-type-vars-with-any-default/104799.