Message358397
I don't know that this is easily solved. By design, issubclass(X, Hashable) checks whether X defines a __hash__ method (or at least has a class attribute __hash__ that isn't None). And because everything ultimately derives from object, which *does* have a __hash__ method (that just hashes the object's address), everything appears hashable, *except* if it explicitly sets __hash__ = None.
You'll find that many classes defined in collections.abc are hashable (e.g. Iterable, Iterator, Sequence, Collection).
But not Set and Mapping. This is because those override __eq__, and there's some deep magic somewhere that sets __hash__ = None in the class dict if __eq__ is overridden.
You could try the following: add an explicit __hash__ = None to all the collection ABCs (in _collections_abc.py) that you think shouldn't define __hash__, and see if all the tests pass.
However, even if they do, I suspect that this may break stuff. E.g. a class that inherits from Iterable but doesn't override __hash__ or __eq__ would suddenly no longer be usable as a dict key.
Since this is only a problem with abstract classes like Iterable or Reversible, maybe we should just ignore the problem? |
|
Date |
User |
Action |
Args |
2019-12-14 15:48:11 | gvanrossum | set | recipients:
+ gvanrossum, rhettinger, stutzbach, Zac Hatfield-Dodds, xtreak, lovi |
2019-12-14 15:48:11 | gvanrossum | set | messageid: <1576338491.39.0.64195443217.issue39046@roundup.psfhosted.org> |
2019-12-14 15:48:11 | gvanrossum | link | issue39046 messages |
2019-12-14 15:48:11 | gvanrossum | create | |
|