Join GitHub today
TypeVar equality broken? #512
FWIW this is actually intentional. I think it was discussed briefly on this tracker, the main motivation is that from the point of view of static type checkers two type variables even with the same name can be different, they follow special scoping rules specified by PEP 484, for example:
T = TypeVar('T') def f(x: T) -> T: ... # the two T's here are the same def g(x: T) -> T: ... # the two T's here are the same, but different from the two T's above
Also this is how type variables work in some other statically typed languages with generics/templates/etc. They get (re-)bound by a class or function definition.
I however don't have any strong opinion on their runtime behavior. @gvanrossum may add to this.
If we all agree that type variables should be treated as "immutable", i.e.