3 ms·
Why is it parsed like that and not as invalid integer literal "0xfor"? edit: 'cause it's a bug! https://bugs.python.org/issue43833 https://bugs.python.org/issu
by kristaps 5y ago
Why is it parsed like that and not as invalid integer literal "0xfor"?
edit: 'cause it's a bug! https://bugs.python.org/issue43833 https://bugs.python.org/issue43833
- pdw 5y agoFor pretty much the same reason that "1+2" is not parsed as an invalid integer.
- _kst_ 5y ago"1+2" is a valid expression consisting of the three tokens "1", "+", and "2". It's permitted to omit whitespace between those tokens. The question is whether "0xfor" is a valid way to represent the two tokens "0xf", "or". My reading of the rules is that it isn't, and that whitespace is required.
- _kst_ 5y agoI read the rules incorrectly. It appears that "0xfor" is a valid way to represent the two tokens "0xf" and "or". The rule, which I initially misinterpreted, is: > Whitespace is needed between two tokens only if their concatenation could otherwise be interpreted as a different token (e.g., ab is one token, but a b is two tokens). Since "0xfor" cannot be interpreted as a different (single) token, whitespace is not needed. (I'm not a fan of this particular consequence of that rule, and I suspect it was not intended, but it says what it says.)