Skip to content

Commit f20ac2e

Browse files
bpo-46820: Fix a SyntaxError in a numeric literal followed by "not in" (GH-31479) (GH-31493)
Fix parsing a numeric literal immediately (without spaces) followed by "not in" keywords, like in "1not in x". Now the parser only emits a warning, not a syntax error. (cherry picked from commit 090e5c4) Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent c596ecb commit f20ac2e

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

Lib/test/test_grammar.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,15 @@ def check_error(test):
251251
check("1e3in x")
252252
check("1jin x")
253253

254+
check("0xfnot in x")
255+
check("0o7not in x")
256+
check("0b1not in x")
257+
check("9not in x")
258+
check("0not in x")
259+
check("1.not in x")
260+
check("1e3not in x")
261+
check("1jnot in x")
262+
254263
with warnings.catch_warnings():
255264
warnings.simplefilter('ignore', SyntaxWarning)
256265
check("0xfis x")
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix parsing a numeric literal immediately (without spaces) followed by "not
2+
in" keywords, like in ``1not in x``. Now the parser only emits a warning,
3+
not a syntax error.

Parser/tokenizer.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,6 +1251,9 @@ verify_end_of_number(struct tok_state *tok, int c, const char *kind)
12511251
else if (c == 'o') {
12521252
r = lookahead(tok, "r");
12531253
}
1254+
else if (c == 'n') {
1255+
r = lookahead(tok, "ot");
1256+
}
12541257
if (r) {
12551258
tok_backup(tok, c);
12561259
if (parser_warn(tok, "invalid %s literal", kind)) {

0 commit comments

Comments
 (0)