
Dec. 4, 2022
6:16 p.m.
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