This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vfaronov
Recipients vfaronov
Date 2016-07-24.12:13:14
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1469362395.06.0.246923750082.issue27605@psf.upfronthosting.co.za>
In-reply-to
Content
Consider the attached example program. I expect it to run successfully, because the Python 3 language reference says [1]:

> For container types such as list, tuple, set, frozenset, dict, or collections.deque, the expression `x in y` is equivalent to `any(x is e or x == e for e in y)`.

and [2]:

> `x==y` calls `x.__eq__(y)`

Instead, under Python 3.5.2, the program crashes with an assertion error, because `dict.__contains__` calls `Bar.__eq__` instead of `Foo.__eq__`.

The same happens if you replace the dict with a set or a frozenset. But if you replace it with a list or a tuple, the behavior is as documented.

This seems to me like a bug in either the implementation or the documentation.

The language reference clearly says [3] that equality should be symmetric "if possible", but is not required to be, and indeed that is hard to guarantee when different classes are involved.

[1] https://docs.python.org/3/reference/expressions.html#membership-test-details
[2] https://docs.python.org/3/reference/datamodel.html#object.__eq__
[3] https://docs.python.org/3/reference/expressions.html#value-comparisons
History
Date User Action Args
2016-07-24 12:13:15vfaronovsetrecipients: + vfaronov
2016-07-24 12:13:15vfaronovsetmessageid: <1469362395.06.0.246923750082.issue27605@psf.upfronthosting.co.za>
2016-07-24 12:13:15vfaronovlinkissue27605 messages
2016-07-24 12:13:14vfaronovcreate