You're right of course. Oh well, it *was* a wild idea.😁
Rob Cliffe
On 04/12/2
On 04/12/2022 18:16, Chris Angelico wrote:
On Mon, 5 Dec 2022 at 05:11, Rob Cliffe via Python-Dev
<python-dev@python.org> wrote:
Wild suggestion:
Make None.__hash__ writable.
E.g.
None.__hash__ = lambda : 0 # Currently raises AttributeError:
'NoneType' object attribute '__hash__' is read-only
Hashes have to be stable. If you change the hash of None after it's
been inserted into a dictionary, you'll get all kinds of entertaining
problems.
class X:
... def __init__(self): self.hash = 0
... def __hash__(self): return self.hash
...
x = X()
d = {x: "This is x"}
x.hash = 1
for key in d: print(key, key in d)
...
<__main__.X object at 0x7f2d07c6f1c0> False
ChrisA
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/python-dev@python.org/message/OVVIKTG7CBN6BII4OBGIXWQJJXYCEO3I/
Code of Conduct: http://python.org/psf/codeofconduct/
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/python-dev@python.org/message/L7JDJFPJKYNHIA7QVYGC74SYAVODM2IX/
Code of Conduct: http://python.org/psf/codeofconduct/