You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2019-08-04.11:14:56.813>created_at=<Date2019-07-22.07:58:57.299>labels= ['interpreter-core', '3.9']
title='Fix minor inconsistency in the order of == operands'updated_at=<Date2019-09-13.09:43:23.212>user='https://github.com/serhiy-storchaka'
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.
Just to add list.__contains__ and others might cause subtle changes as noted. One example is around discussion at #14700 (comment) where my code to fix mock.ANY was depending on this behavior to work on master and didn't work with 3.8 since it's not backported. mock.ANY depends on the order of operands.
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: