[issue36617] The rich comparison operators are second class citizens

Eric V. Smith report at bugs.python.org
Fri Apr 19 12:59:49 EDT 2019


Eric V. Smith <eric at trueblade.com> added the comment:

I assume the OP is using the stdlib parser module just to show what is a syntax error and what isn't. But most of the characters in the example strings aren't required, so it can be simplified.

Here is a simpler case demonstrating what I think the OP is trying to say.

This is not a syntax error:
>>> [*0<<1]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'int' object is not iterable

(Ignore the type error, this shows that it's syntactically valid.)

But this is a syntax error:
>>> [*0<=1]
  File "<stdin>", line 1
    [*0<=1]
        ^
SyntaxError: invalid syntax

Both of these are treated the same way, as not syntax errors:
>>> f(*0==1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'f' is not defined
>>> f(*0<=1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'f' is not defined

Here's the above, using parser:

>>> import parser
>>> parser.expr("[*0<<1]")
<parser.st object at 0x7fa18d93a430>

>>> parser.expr("[*0<=1]")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 1
    [*0<=1]
        ^
SyntaxError: invalid syntax

>>> parser.expr("f(*0<<1)")
<parser.st object at 0x7fa18d93a470>

>>> parser.expr("f(*0<=1)")
<parser.st object at 0x7fa18d93a410>

I'm not sure this is worth fixing. Maybe if someone can find where in the grammar this is caused, and understands the side effects of fixing it, it could be addressed. But I expect it to be non-trivial.

----------
components: +Interpreter Core
nosy: +eric.smith
versions: +Python 3.7

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


More information about the Python-bugs-list mailing list