On 2019-10-20 19:31:43 +0200, Steve White wrote:
> The point is, I don't think __eq__() is ever called in a situation as
> described in my post,

This is only guaranteed if the hash is actually stored within the dict.
This seems to be the case in the CPython implementation, but there are
other ways to implement a hash table which don't store the hashes
explicitely (in fact, I don't think any of the variants we learned about
at university 30 years ago did this).

So your code may work with CPython, but not other Python implementations.
Worse, it may stop working with future CPython versions if the dict
implementation is changed.

But even if you are fine with that, by using a different equality
criterion for dicts than for everything else, your code is violating one
of every Python programmer's core assumptions. This will very likely trip
somebody up (maybe yourself in two years).

        hp

-- 
   _  | Peter J. Holzer    | we build much bigger, better disasters now
|_|_) |                    | because we have much more sophisticated
| |   | h...@hjp.at         | management tools.
__/   | http://www.hjp.at/ | -- Ross Anderson <https://www.edge.org/>

Attachment: signature.asc
Description: PGP signature

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to