Skip to content

bpo-37648: Fixed minor inconsistency in some __contains__. #14904

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 4, 2019

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Jul 22, 2019

The collection's item is now always at the left and
the needle is on the right of ==.

https://bugs.python.org/issue37648

The collection's item is now always at the left and
the needle is on the right of ==.
Copy link
Contributor

@aeros aeros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to assess if this PR changed the output of list.__contains__() and tuple.__contains__() (particularly in cases where the __eq__() is incorrectly implemented, as mentioned in the issue), I performed the following comparison between cpython master and the PR branch:

cpython master:
image

PR branch:
image

This was by no means a thorough assessment of the changes, but I figured it might be useful to perform a basic comparison on two variables where (a == b) != (b == a) for list.__contains__() and tuple.__contains__().

I approve of this PR because it provides a higher degree of consistency with the positioning of the needle, and from my understanding, there's no functional disadvantage from implementing this change. Though, I'm not certain if there's any specific cases where the change results in a difference of output in the specific case of __contains__() for list and tuple. Let me know if there are any.

Copy link
Contributor

@aeros aeros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed a couple of trivial typos in the news entry:

@serhiy-storchaka serhiy-storchaka merged commit 18b711c into python:master Aug 4, 2019
@serhiy-storchaka serhiy-storchaka deleted the needle-right branch August 4, 2019 11:12
lisroach pushed a commit to lisroach/cpython that referenced this pull request Sep 10, 2019
…14904)

The collection's item is now always at the left and
the needle is on the right of ==.
DinoV pushed a commit to DinoV/cpython that referenced this pull request Jan 14, 2020
…14904)

The collection's item is now always at the left and
the needle is on the right of ==.
websurfer5 pushed a commit to websurfer5/cpython that referenced this pull request Jul 20, 2020
…14904)

The collection's item is now always at the left and
the needle is on the right of ==.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants