Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Recognize
Hashable
as a real protocol (#11802)
When this piece of code was checked: ```python from typing import Awaitable, Hashable, Union, Tuple, List obj: Union[Tuple[int], List[int]] if isinstance(obj, Hashable): reveal_type(obj) ``` Mypy revealed that `Hashable` is `() -> object`. It happened, because [`is_subtype(explicit_type, default_ret_type, ignore_type_params=True)`](https://github.com/python/mypy/blob/56684e43a14e3782409c47e99bb47191d631a3de/mypy/typeops.py#L130) was `True`, where `explicit_type=object` and `default_ret_type=Hashable`. It happened because `object` has `__hash__` method. The only thing that popped out of my head is to simply exclude protocols from this condition. I guess that we might double check protocols with `__new__` and `__init__` to be sure. But, I am not able to think of proper test cases for this. Any ideas? Or is my single test good enough? I am adding `pythoneval` test, because of the complexity in how `Hashable` is defined and analyzed in real life. Closes #11799
- Loading branch information