Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include example of OrderedDict's intransitive __eq__ implementation? #77

Closed
jab opened this issue Mar 27, 2018 · 5 comments
Closed

Include example of OrderedDict's intransitive __eq__ implementation? #77

jab opened this issue Mar 27, 2018 · 5 comments
Milestone

Comments

@jab
Copy link

jab commented Mar 27, 2018

The second snippet in cosmologicon/pywat#38 provides an example of such a big WTF in Python that Raymond Hettinger himself even called OrderedDict's intransitive equality a mistake. Any interest in including that here?

@satwikkansal
Copy link
Owner

Interesting! I'll add it in the next update, or if you like, you can submit a PR for this. Thanks for sharing it 😄

@chris-rands
Copy link

Do you have a link for where Raymond said this? I agree the behaviour is not obvious, but it is intended and documented:

Equality tests between OrderedDict objects are order-sensitive and are implemented as list(od1.items())==list(od2.items()). Equality tests between OrderedDict objects and other Mapping objects are order-insensitive like regular dictionaries. This allows OrderedDict objects to be substituted anywhere a regular dictionary is used.

https://docs.python.org/3/library/collections.html#ordereddict-objects

@jab
Copy link
Author

jab commented Apr 26, 2018

screen shot 2018-04-26 at 16 29 11

This allows OrderedDict objects to be substituted anywhere a regular dictionary is used.

Well, not exactly anywhere, as my od == od2 example from cosmologicon/pywat#38 demonstrates. This imprecision is a bug in the docs. An edge case bug, but still a bug.

@chris-rands
Copy link

Interesting thanks, I guess that either way the behaviour would surprise some users. I'm not convinced this is a doc bug, but file it as one if you think so https://bugs.python.org/

@satwikkansal satwikkansal added this to the 3.0 milestone Dec 4, 2018
satwikkansal added a commit that referenced this issue Jun 9, 2019
@satwikkansal
Copy link
Owner

Thanks for suggesting this @jab , this was actually one of very few genuine WTFs I've observed. Added in the above commit ^^, feel free to have a look and point out any corrections / missing details.

satwikkansal added a commit that referenced this issue Oct 28, 2019
muscliary pushed a commit to muscliary/wtfpython that referenced this issue Sep 12, 2023
muscliary pushed a commit to muscliary/wtfpython that referenced this issue Sep 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants