Wild suggestion:
    Make None.__hash__ writable.
E.g.
    None.__hash__ = lambda : 0 # Currently raises AttributeError: 'NoneType' object attribute '__hash__' is read-only
Best wishes
Rob Cliffe

On 01/12/2022 11:02, Oscar Benjamin wrote:
On Thu, 1 Dec 2022 at 06:56, Chris Angelico <ros...@gmail.com> wrote:
On Thu, 1 Dec 2022 at 17:26, Yoni Lavi <yoni.lav...@gmail.com> wrote:
So it's not like it's even possible to require this generally for all objects.
Well, I mean, in theory you could require that objects whose hash
isn't otherwise defined get given the hash of zero. That doesn't
violate any of the actual rules of hashes, but it does make those
hashes quite suboptimal :)

It's interesting how id() and hash() have opposite requirements (id
must return a unique number among concurrently-existing objects, hash
must return the same number among comparing-equal objects), yet a hash
can be built on an id.
This also demonstrates a significant reason why None is special: it's
a singleton that only compares equal to itself. The reason for using
id for hash in other cases is to make different instances have
different hashes but there is only ever one instance of None. A
singleton class can have a hash function that matches identity based
equality without using id: any constant hash function will do.

--
Oscar
_______________________________________________
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/MTTJJN2HHP3A264DN3CAWSXITHRMLLUW/
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/XRASAGN52DAM7EAKJOYSWHJEKFAP2JPT/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to