Message348287
There is two ways to write the comparison when we search an item equal to the needle:
item == needle
and
needle == item
In most cases they get the same result. But if __eq__ of the item or the needle is not correctly implemented (returns False instead of NotImplemented for unsupported types) the order can matter. We want the behavior be consistent in all cases.
The majority of the code uses needle on the right side of the == operator. But there are few outliners:
* tuple.__contains__ and list.__contains__. They code is different from the code used in methods count(), index(), remove() where needle is on the right.
* The general implementation of the "in" operator for iterators (see PySequence_Contains).
* dictitems.__contains__.
* The copy of list_contains in _ssl.c.
* The C implementation of _asyncio.Future.remove_done_callback. It differs from the Python implementation.
In all other code (many tens of occurrences) needle is on the right.
I think it is worth to fix the minor inconsistency in these few places.
See also the discussion on Python-Dev: https://mail.python.org/archives/list/python-dev@python.org/thread/VSV4K4AOKM4CBQMOELPFV5VMYALPH464/. |
|
Date |
User |
Action |
Args |
2019-07-22 07:58:57 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka |
2019-07-22 07:58:57 | serhiy.storchaka | set | messageid: <1563782337.34.0.926786223428.issue37648@roundup.psfhosted.org> |
2019-07-22 07:58:57 | serhiy.storchaka | link | issue37648 messages |
2019-07-22 07:58:56 | serhiy.storchaka | create | |
|