[New-bugs-announce] [issue38769] generators are currently hashable
Anthony Sottile
report at bugs.python.org
Mon Nov 11 14:40:25 EST 2019
New submission from Anthony Sottile <asottile at umich.edu>:
We recently found a bug in one of our codebases that looked ~roughly like this:
class C:
...
def __hash__(self):
return hash((v for k, v in sorted(self.__dict__.items())))
which resulted in a production bug
The *intention* was to hash a tuple of those elements but the author had forgotten the `tuple(...)` call (or incorrectly assumed a parenthesized generator was a tuple comprehension) -- either way it seems wrong that generators are currently hashable as they are mutable
Thoughts on `__hash__ = None` for generators?
----------
components: Interpreter Core
messages: 356382
nosy: Anthony Sottile
priority: normal
severity: normal
status: open
title: generators are currently hashable
versions: Python 3.9
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38769>
_______________________________________
More information about the New-bugs-announce
mailing list