New submission from Serhiy Storchaka <[email protected]>:
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/[email protected]/thread/VSV4K4AOKM4CBQMOELPFV5VMYALPH464/.
----------
components: Interpreter Core
messages: 348287
nosy: serhiy.storchaka
priority: normal
severity: normal
status: open
title: Fix minor inconsistency in the order of == operands
versions: Python 3.9
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue37648>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com