Skip to content

bpo-32118: Document that, in sequence comparisons, reflexivity means otherwise u…#4514

Closed
dubslow wants to merge 2 commits into
python:masterfrom
dubslow:sequence-comparison-reflexivity-note
Closed

bpo-32118: Document that, in sequence comparisons, reflexivity means otherwise u…#4514
dubslow wants to merge 2 commits into
python:masterfrom
dubslow:sequence-comparison-reflexivity-note

Conversation

@dubslow

@dubslow dubslow commented Nov 23, 2017

Copy link
Copy Markdown

…norderable objects are ignored

In sequence comparisons, the enforcement of reflexivity of elements means that only non-identical elements are actually compared. The docs then note, with example, that non-reflexive elements thus always "compare" equal inside the sequence.

This patch adds a second corollary, that non-orderable singletons (e.g. None) will also not break sequence comparison.

Yes, the consequence is logically derivable from the statement "element identity is compared first, and element comparison is performed only for distinct elements", but the first example is given because "For non-reflexive elements, the result is different than for strict element comparison, and may be surprising", which also holds for the example I add here: different from strict element comparison, which may lead to otherwise surprising results (it sure was surprising to me when I expected a list with Nones to fail to compare, hence why I went trawling through the docs). In the manner of the first example, explicit is better than implicit, and (I believe) it will be helpful for readers to have this second consequence demonstrated.

!!! If this is a backport PR (PR made against branches other than master),
please ensure that the PR title is in the following format:

[X.Y] <title from the original PR> (GH-NNNN)

Where: [X.Y] is the branch name, e.g. [3.6].

GH-NNNN refers to the PR number from master.

PLEASE: Remove this headline!!!

https://bugs.python.org/issue32118

…norderable objects are ignored

In sequence comparisons, the enforcement of reflexivity of elements means that only non-identical elements are actually compared. The docs then note, with example, that non-reflexive elements thus always "compare" equal inside the sequence.

This patch adds a second corollary, that non-orderable singletons (e.g. None) will also not break sequence comparison.

Yes, the consequence is logically derivable from the statement "element identity is compared first, and element comparison is performed only for distinct elements", but the first example is given because "For non-reflexive elements, the result is different than for strict element comparison, and may be surprising", which also holds for the example I add here: different from strict element comparison, which may lead to otherwise surprising results (it sure was surprising to me when I expected a list with Nones to fail to compare, hence why I went trawling through the docs). In the manner of the first example, explicit is better than implicit, and (I believe) it will be helpful for readers to have this second consequence demonstrated.
@the-knights-who-say-ni

Copy link
Copy Markdown

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA).

Unfortunately our records indicate you have not signed the CLA. For legal reasons we need you to sign this before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

Thanks again to your contribution and we look forward to looking at it!

@rhettinger rhettinger left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

See the comment in the issue tracker. I prefer not to make this patch or anything else that looks like an exception to an exception with a list of examples are all atypical and weird). It makes Python look like a minefield of special cases and doesn't facilitate building a clean mental model that allows people to make successful predictions.

@terryjreedy terryjreedy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree that the current doc might be improved.

However, the phenomenon noted is not about reflexivity nor about singletons. The example does not need the 'is' and '==' parts. I am not sure this is the best place for an addition. I think the patch as is should be rejected.

I will look at the current doc and try to suggest something that I think is better.

@bedevere-bot

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@dubslow

dubslow commented Nov 28, 2017

Copy link
Copy Markdown
Author

@terryjreedy I like your version (on bpo) better. I'm closing this PR in favor of TJR's suggestion (other than perhaps the one word grammar patch in 5d5fe0d)

@dubslow dubslow closed this Nov 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants