cpython: 4ad33d82193d (original) (raw)
Mercurial > cpython
changeset 91061:4ad33d82193d 3.4
allow the keyword else immediately after (no space) an integer (closes #21642) [#21642]
Benjamin Peterson benjamin@python.org | |
---|---|
date | Sat, 07 Jun 2014 12:36:39 -0700 |
parents | d23cea976f46 |
children | d5998cca01a8 0c712828fb6e |
files | Lib/test/test_grammar.py Misc/NEWS Parser/tokenizer.c |
diffstat | 3 files changed, 24 insertions(+), 5 deletions(-)[+] [-] Lib/test/test_grammar.py 6 Misc/NEWS 4 Parser/tokenizer.c 19 |
line wrap: on
line diff
--- a/Lib/test/test_grammar.py +++ b/Lib/test/test_grammar.py @@ -80,6 +80,12 @@ class TokenTests(unittest.TestCase): x = .3e14 x = 3.1e4
- def test_float_exponent_tokenization(self):
# See issue 21642.[](#l1.8)
self.assertEqual(1 if 1else 0, 1)[](#l1.9)
self.assertEqual(1 if 0else 0, 0)[](#l1.10)
self.assertRaises(SyntaxError, eval, "0 if 1Else 0")[](#l1.11)
+ 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)
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,10 @@ Release date: XXXX-XX-XX 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"
--- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -1597,15 +1597,24 @@ tok_get(struct tok_state *tok, char **p_ } while (isdigit(c)); } if (c == 'e' || c == 'E') {
exponent:[](#l3.7)
int e;[](#l3.8)
exponent:[](#l3.9)
e = c;[](#l3.10) /* Exponent part */[](#l3.11) c = tok_nextc(tok);[](#l3.12)
if (c == '+' || c == '-')[](#l3.13)
if (c == '+' || c == '-') {[](#l3.14) c = tok_nextc(tok);[](#l3.15)
if (!isdigit(c)) {[](#l3.16)
tok->done = E_TOKEN;[](#l3.17)
if (!isdigit(c)) {[](#l3.18)
tok->done = E_TOKEN;[](#l3.19)
tok_backup(tok, c);[](#l3.20)
return ERRORTOKEN;[](#l3.21)
}[](#l3.22)
} else if (!isdigit(c)) {[](#l3.23) tok_backup(tok, c);[](#l3.24)
return ERRORTOKEN;[](#l3.25)
tok_backup(tok, e);[](#l3.26)
*p_start = tok->start;[](#l3.27)
*p_end = tok->cur;[](#l3.28)
return NUMBER;[](#l3.29) }[](#l3.30) do {[](#l3.31) c = tok_nextc(tok);[](#l3.32)