Author vfaronov
Recipients vfaronov
Date 2016-07-24.12:13:14
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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.

Date User Action Args
2016-07-24 12:13:15vfaronovsetrecipients: + vfaronov
2016-07-24 12:13:15vfaronovsetmessageid: <>
2016-07-24 12:13:15vfaronovlinkissue27605 messages
2016-07-24 12:13:14vfaronovcreate