[issue43833] Unexpected Parsing of Numeric Literals Concatenated with Boolean Operators

sco1 report at bugs.python.org
Tue Apr 13 14:27:19 EDT 2021


New submission from sco1 <sco1.git at gmail.com>:

Came across this riddle today:

>>> [0x_for x in (1, 2, 3)]
[15]

Initially I thought this was related to PEP 515 but the unexpected behavior extends to simpler examples as well, such as:

>>> x = 5
>>> 123or x
123
>>> 123and x
5

I'm not familiar enough with C to understand why this is being parsed/tokenized this way, but this seems like it should instead be a SyntaxError. This appears to be fairly old behavior, as the non-underscored version works back to at least 2.7.

And a bonus:

>>> 0x1decade or more
31378142

----------
messages: 390981
nosy: sco1
priority: normal
severity: normal
status: open
title: Unexpected Parsing of Numeric Literals Concatenated with Boolean Operators
type: behavior
versions: Python 3.10, Python 3.7, Python 3.8, Python 3.9

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


More information about the Python-bugs-list mailing list