[New-bugs-announce] [issue36617] The rich comparison operators are second class citizens

Dan Snider report at bugs.python.org
Fri Apr 12 13:07:05 EDT 2019


New submission from Dan Snider <mr.assume.away at gmail.com>:

The rich comparison operators have an (far as I can tell, unnecessary) limitation compared to the other binary operators, being that the result of an unparenthesized comparison expression cannot be unpacked using the *iterable "unpack" operator (does that thing have an official name?)

Here's a silly demonstration of what I'm talking about:
 
 >>> if 1:
...     parser.expr("[*+-~d<<b-~+_]") # all binary/unary number ops work
...     parser.expr("[*+-~d<=b-~+_]")
...
<parser.st object at 0x011D4A58>
Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
  File "<string>", line 1
    [*+-~d<=b-~+_]
           ^
SyntaxError: invalid syntax


>>> if 1:
...     parser.expr("f(*+d<<-b)")
...     parser.expr("f(*+d<=-b)")
...
<parser.st object at 0x01205DD0>
<parser.st object at 0x011D49C8>


Because the limitation is not present for function calls, I suspect this is simply a "typo" that's gone unnoticed for years, due to nobody ever trying it. I'm hardly an expert on the parser and can barely read the grammar file so i might be totally wrong here. But then, what would be the difference between the expressions: [*a+b+c+d, *e-f] and [*a<b<c<d, *e<f], if a, b, c, d, e, and f are eg. instances of the class:

    >>> class S(list): __lt__ = list.__add__

----------
messages: 340084
nosy: bup
priority: normal
severity: normal
status: open
title: The rich comparison operators are second class citizens

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36617>
_______________________________________


More information about the New-bugs-announce mailing list