A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2014-March/133274.html below:

[Python-Dev] Intricacies of calling __eq__

[Python-Dev] Intricacies of calling __eq__ [Python-Dev] Intricacies of calling __eq__Mark Shannon mark at hotpy.org
Wed Mar 19 11:10:42 CET 2014
On 18/03/14 07:52, Maciej Fijalkowski wrote:
> Hi
>
> I have a question about calling __eq__ in some cases.
>
> We're thinking about doing an optimization where say:
>
> if x in d:
>     return d[x]
>
> where d is a dict would result in only one dict lookup (the second one
> being constant folded away). The question is whether it's ok to do it,
> despite the fact that it changes the semantics on how many times
> __eq__ is called on x.

Yes it is OK. The number of equality checks is not part of the specification of
the dictionary. In fact, it differs between a 32 and 64 bit build of the same code.

Consider two objects that hash to 2**33+1 and 2**34+1 respectively.
On a 32 bit machine their truncated hashes are both 1, so they must be distinguished
by an equality test. On a 64 bit machine their hashes are distinct and no equality
check is required.

Cheers,
Mark.
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4