New submission from Dan Snider <[email protected]>:
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 <[email protected]>
<https://bugs.python.org/issue36617>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com