Skip to content

Commit 80b5134

Browse files
committed
Handle more cases (SyntaxWarning's currently)
1 parent 12b7257 commit 80b5134

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

Lib/test/test_grammar.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,17 @@ def check(test, error=False):
193193
("1jz", 3, "imaginary"),
194194
("0xI", 3, "hexadecimal"),
195195
("0bz", 3, "binary"),
196+
# SyntaxWarning's currently:
197+
("1or 0", 2, " decimal"),
198+
("0or 0", 3, "octal"),
196199
])
197200
def test_end_of_numerical_literals_offset(self, source, offset, msg):
198201
# gh-149277: verify the error caret points at the first invalid
199202
# character, not the last valid digit.
200-
with self.assertRaises(SyntaxError) as cm:
201-
compile(source, "<test>", "eval")
203+
with warnings.catch_warnings():
204+
warnings.simplefilter("error", SyntaxWarning)
205+
with self.assertRaises(SyntaxError) as cm:
206+
compile(source, "<test>", "eval")
202207
self.assertEqual(cm.exception.offset, offset)
203208
self.assertIn(msg, cm.exception.msg)
204209

Parser/lexer/number.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,11 @@ verify_end_of_number(struct tok_state *tok, int c, const char *kind) {
7070
r = lookahead(tok, "ot");
7171
}
7272
if (r) {
73-
tok_backup(tok, c);
7473
if (_PyTokenizer_parser_warn(tok, PyExc_SyntaxWarning,
7574
"invalid %s literal", kind))
7675
{
7776
return 0;
7877
}
79-
tok_nextc(tok);
8078
}
8179
else /* In future releases, only error will remain. */
8280
if (c < 128 && is_potential_identifier_char(c)) {

0 commit comments

Comments
 (0)