This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients Dubslow, docs@python, r.david.murray, rhettinger, terry.reedy
Date 2017-11-25.22:49:18
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1511650158.88.0.213398074469.issue32118@psf.upfronthosting.co.za>
In-reply-to
Content
(Raymond, I wrote this before reading your message, but I believe it provides what you requested.  There is nothing special about None that is relevant to sequence comparison.  Nans just happen to be the only built-in non-reflexive objects (that I know of, thank goodness).)

This issue is about order comparisons *also* being defined on a single object in a sequence and therefore also possibly giving a different result.  Title revised to be clearer and short enough to all be visible.  Demonstration:

>>> a = object()
>>> a == a, a != a  # but a < a, a <= a, a >= a, a > a raise TypeError
(True, False)
>>> la = [a]
>>> la == la, la != la, la < la, la <= la, la >= la, la > la
(True, False, False, True, True, False)

Comparison of two sequences infers from identity all 6 rich comparison results on a single object in corresponding positions of the two sequences.

This has nothing to do with the object being a singleton, other than a singleton being a single object.  The enforcement of reflexivity and enforcement of consistent order on single objects are related, but the latter did not have to follow from the first.  The presentation of order, in the patch, by reference to singletons and reflexivity, does not work.  As I said in review, the example is too long and wrongly placed.  I think using a generic object instead of None would also be better.

I would like to rewrite the sequence comparison paragraphs after the first as something like the following.
---

Sequences compare lexicographically using comparison of corresponding elements.  The two objects are first compared for identity.  If they are distinct, they are compared normally.  If they are the same object, the self comparisons are inferred: '==', '>=', and '<=' are true, while '!=', '>', and '<' are false.

By design, the inferred self comparisons for sequences sometimes give different results than would strict element comparison.  Instances of an unordered class become ordered with respect to themselves instead of raising a TypeError.

>>> a = object()
>>> a < a          # By default, objects are not ordered
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: '>=' not supported between instances of 'object' and 'object'
>>> [a] < [a]
False              # Sequence comparison orders an object versus itself

Even anti-reflexive not-a-number values, for example, are treated as reflexive (meaning a == a always).

<insert current nan example> 
---

This re-write describes sequence comparison in one paragraph, instead of putting the details in the middle of the next paragraph.  The next paragraph describes the two possible consequences of inferring comparisons from identify: a result instead of a raise, and a different result.
History
Date User Action Args
2017-11-25 22:49:18terry.reedysetrecipients: + terry.reedy, rhettinger, r.david.murray, docs@python, Dubslow
2017-11-25 22:49:18terry.reedysetmessageid: <1511650158.88.0.213398074469.issue32118@psf.upfronthosting.co.za>
2017-11-25 22:49:18terry.reedylinkissue32118 messages
2017-11-25 22:49:18terry.reedycreate