[issue38769] generators are currently hashable

Raymond Hettinger report at bugs.python.org
Mon Nov 11 16:21:22 EST 2019


Raymond Hettinger <raymond.hettinger at gmail.com> added the comment:

> there are other such mutable objects in python which do define
> __hash__ = None such as list and dict

Those objects compare on their contents, not on object identity.

Take a look at how hashing works in dataclasses.  You can have a mix of mutable and immutable fields as long as both __eq__ and __hash__ depend on only the immutable fields.

Also, take a look at database cursor objects.  Both __eq__ and __hash__ use object identity even though fetchone() advances the internal state (just like an iterator).

Anyway, the breaking of existing working code makes this a non-starter.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38769>
_______________________________________


More information about the Python-bugs-list mailing list