[issue21979] SyntaxError not raised on "0xaor 1"

2014-07-14 Thread Mark Dickinson
Mark Dickinson added the comment: > Mark, can you explain why the first example is valid syntax, but the second > one is not: Looks like Eric beat me to it! As he explained, it's the "maximal munch" rule at work: the tokenizer matches as much as it can for each token. You see similar effects

[issue21979] SyntaxError not raised on "0xaor 1"

2014-07-14 Thread Eric V. Smith
Eric V. Smith added the comment: To be more clear: the parser takes the longest token that could be valid. Since "n" can't be part of a hex number, parsing stops there, returning "0xaa" as the first token. So: >>> 0xaaif 1 else 0 170 >>> hex(0xaaif 1 else 0) '0xaa' >>> -- __

[issue21979] SyntaxError not raised on "0xaor 1"

2014-07-14 Thread Mika Eloranta
Mika Eloranta added the comment: OK, I see... "0xfand 1" is ambiguous "(0xfa)nd 1" vs. "(0xf)and 1". So, while a bit weird, the behavior is consistent: >>> 123not in [], 0xfnot in [], 0xfor 1, 0xafor 1, 0xfin [] (True, True, 15, 175, False) -- ___ P

[issue21979] SyntaxError not raised on "0xaor 1"

2014-07-14 Thread Eric V. Smith
Changes by Eric V. Smith : -- stage: -> resolved ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.

[issue21979] SyntaxError not raised on "0xaor 1"

2014-07-14 Thread Eric V. Smith
Eric V. Smith added the comment: 0xaand 1 is parsed as 0xaa nd 1 which is not valid syntax. -- nosy: +eric.smith ___ Python tracker ___ _

[issue21979] SyntaxError not raised on "0xaor 1"

2014-07-14 Thread Mika Eloranta
Mika Eloranta added the comment: Mark, can you explain why the first example is valid syntax, but the second one is not: >>> 0xaor 1 10 >>> 0xaand 1 File "", line 1 0xaand 1 ^ SyntaxError: invalid syntax I do understand how "0xaor 1" is currently parsed, but I'm not still conv

[issue21979] SyntaxError not raised on "0xaor 1"

2014-07-14 Thread Mark Dickinson
Mark Dickinson added the comment: Surprisingly, this is valid syntax. Your first line is parsed as: 0xf or (python is weird in ways) Because `or` is short-circuiting, its right-hand operand (which is also valid syntactically, being a chained comparison) is never evaluated, so we don't see

[issue21979] SyntaxError not raised on "0xaor 1"

2014-07-14 Thread Mika Eloranta
New submission from Mika Eloranta: The following are expected to raise SyntaxError, but they don't: >>> 0xfor python is weird in ways 15 >>> [0xaor 1, 0xbor 1, 0xcor 1, 0xdor 1, 0xeor 1, 0xfor 1] [10, 11, 12, 13, 14, 15] Verified on v2.7.1 and v3.3.2. Probably affects all versions. --