Skip to content

Commit 090e5c4

Browse files
bpo-46820: Fix a SyntaxError in a numeric literal followed by "not in" (GH-31479)
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.
1 parent 74127b8 commit 090e5c4

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
@@ -1253,6 +1253,9 @@ verify_end_of_number(struct tok_state *tok, int c, const char *kind)
12531253
else if (c == 'o') {
12541254
r = lookahead(tok, "r");
12551255
}
1256+
else if (c == 'n') {
1257+
r = lookahead(tok, "ot");
1258+
}
12561259
if (r) {
12571260
tok_backup(tok, c);
12581261
if (parser_warn(tok, "invalid %s literal", kind)) {

0 commit comments

Comments
 (0)