Issue 27588: Type (typing) objects are hashable and comparable for equality but this is not documented (original) (raw)
The type objects constructed by the metaclasses in the typing module are hashable and comparable for equality:
>>> from typing import *
>>> {Mapping[str, int], Mapping[int, str]}
{typing.Mapping[int, str], typing.Mapping[str, int]}
>>> Union[str, int, float] == Union[float, int, str]
True
>>> List[int] == List[float]
False
but this is not clearly documented in the documentation for the typing module (there are a handful of examples using equality, but it's not explicit that these are runnable).
It would be nice if there were explicit documentation for these properties of type objects.