[New-bugs-announce] [issue37648] Fix minor inconsistency in the order of == operands

Serhiy Storchaka report at bugs.python.org
Mon Jul 22 03:58:57 EDT 2019


New submission from Serhiy Storchaka <storchaka+cpython at gmail.com>:

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/.

----------
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 <report at bugs.python.org>
<https://bugs.python.org/issue37648>
_______________________________________


More information about the New-bugs-announce mailing list