Description
Bug description:
In the last two years, Python started issuing superfluous misleading warning for perfectly valid code.
Examples:
[ord(x)>>5for x in h]
b'\x03'if P.y%2else b'\x02'
In the first example, 5for
is not an invalid decimal literal, it is a decimal literal 5
followed by keyword for
which a perfectly valid sequence of lexical elements. Similar to second example 2else
.
An invalid decimal literal would be using a decimal literal that starts with number:
2for = 15
Where 2for
is used as a name of variable. I would personally call it an invalid identifier (so even official use is confusing).
But the cases above are not the cases of invalid literal, they are correctly false. This worked due to how lexical analyzers are constructed as way back as C or even longer. Why did Python start issuing this misleading warning out of the blue?
Also note, that b'\x03'if
doesn't produce any warning.
Can this nonsense be suppressed?
I would note that 10 years ago I wrote code obfuscation/minimizer and deobfuscator/deminizer that decided when whitespace needs to be introduced between two lexical elements based on the fact that you don't need to introduce if joining of two adjacent lexical elements doesn't produce a new lexical element.
CPython versions tested on:
3.11
Operating systems tested on:
Linux