Kill __subclasscheck__ by ilevkivskyi · Pull Request #283 · python/typing
@gvanrossum
Thank you for merging this!
I will submit a new PR for Union[int, Any] in typing.py and probably also PR for PEPs 484 and 483.
This is a good catch, I didn't notice this while editing PEP 483. The point is that type is characterized by two sets: set of values and set of functions (methods), as mentioned in PEP 483. With such definition neither int is not a subtype of Any (since int has less methods) nor vice versa (since Any has more values). The fact that Any is at the same time at the top of type hierarchy (it has all values) and at its bottom (it has all methods) requires us to introduce two different concepts: subtype and compatibility.
Actually, now I think that Any should be considered a subtype of object. Indeed, both have all values, but Any has more methods, therefore it is a subtype of object. This, in turn, means that Union[object, Any] should be simplified to just object. For example, if x has type Union[object, Any] then the only way to call x.lower() is when x is not object, but this is not possible:
x: Union[object, Any] x.lower() # this should be rejected if not isinstance(x, object): x.lower() # this should be allowed, but it is not reachable
What do you think?
(If it will help, the relation between object and Any is similar to relation between, e.g., Mapping and MutableMapping, they both have the same set of values, but MutableMapping has more methods, therefore it is a subtype of Mapping.)