changeset: 91063:d5998cca01a8 parent: 91060:b167df2912d6 parent: 91061:4ad33d82193d user: Benjamin Peterson date: Sat Jun 07 12:39:51 2014 -0700 files: Lib/test/test_grammar.py Misc/NEWS Parser/tokenizer.c description: merge 3.4 (#21642) diff -r b167df2912d6 -r d5998cca01a8 Lib/test/test_grammar.py --- a/Lib/test/test_grammar.py Sun Jun 08 00:00:13 2014 +1000 +++ b/Lib/test/test_grammar.py Sat Jun 07 12:39:51 2014 -0700 @@ -80,6 +80,12 @@ x = .3e14 x = 3.1e4 + def test_float_exponent_tokenization(self): + # See issue 21642. + self.assertEqual(1 if 1else 0, 1) + self.assertEqual(1 if 0else 0, 0) + self.assertRaises(SyntaxError, eval, "0 if 1Else 0") + def test_string_literals(self): x = ''; y = ""; self.assertTrue(len(x) == 0 and x == y) x = '\''; y = "'"; self.assertTrue(len(x) == 1 and x == y and ord(x) == 39) diff -r b167df2912d6 -r d5998cca01a8 Misc/NEWS --- a/Misc/NEWS Sun Jun 08 00:00:13 2014 +1000 +++ b/Misc/NEWS Sat Jun 07 12:39:51 2014 -0700 @@ -10,6 +10,10 @@ Core and Builtins ----------------- +- Issue #21642: If the conditional if-else expression, allow an integer written + with no space between itself and the ``else`` keyword (e.g. ``True if 42else + False``) to be valid syntax. + - Issue #21523: Fix over-pessimistic computation of the stack effect of some opcodes in the compiler. This also fixes a quadratic compilation time issue noticeable when compiling code with a large number of "and" diff -r b167df2912d6 -r d5998cca01a8 Parser/tokenizer.c --- a/Parser/tokenizer.c Sun Jun 08 00:00:13 2014 +1000 +++ b/Parser/tokenizer.c Sat Jun 07 12:39:51 2014 -0700 @@ -1603,15 +1603,24 @@ } while (isdigit(c)); } if (c == 'e' || c == 'E') { - exponent: + int e; + exponent: + e = c; /* Exponent part */ c = tok_nextc(tok); - if (c == '+' || c == '-') + if (c == '+' || c == '-') { c = tok_nextc(tok); - if (!isdigit(c)) { - tok->done = E_TOKEN; + if (!isdigit(c)) { + tok->done = E_TOKEN; + tok_backup(tok, c); + return ERRORTOKEN; + } + } else if (!isdigit(c)) { tok_backup(tok, c); - return ERRORTOKEN; + tok_backup(tok, e); + *p_start = tok->start; + *p_end = tok->cur; + return NUMBER; } do { c = tok_nextc(tok);