Skip to content

Commit cd9bf16

Browse files
committed
As it's requires a PEP, lets trigger a syntax warning
1 parent 9af396d commit cd9bf16

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

Lib/test/test_grammar.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ def test_plain_integers(self):
7777
def test_attrs_on_hexintegers(self):
7878
good_meth = [m for m in dir(int) if not m.startswith('_')]
7979
for m in good_meth:
80-
self.assertEqual(eval('0x1.' + m), eval('(0x1).' + m))
80+
with self.assertWarns(SyntaxWarning):
81+
v = eval('0x1.' + m)
82+
self.assertEqual(v, eval('(0x1).' + m))
8183
self.check_syntax_error('0x1.spam', "invalid hexadecimal literal",
8284
lineno=1, offset=4)
8385
self.check_syntax_error('0x1.foo', "invalid hexadecimal literal",

Lib/test/test_zstd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,7 @@ def test_is_raw(self):
12391239
ZstdDict(desk333=345)
12401240

12411241
def test_invalid_dict(self):
1242-
DICT_MAGIC = 0xEC30A437.to_bytes(4, byteorder='little')
1242+
DICT_MAGIC = (0xEC30A437).to_bytes(4, byteorder='little')
12431243
dict_content = DICT_MAGIC + b'abcdefghighlmnopqrstuvwxyz'
12441244

12451245
# corrupted

Parser/lexer/lexer.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,11 @@ tok_get_normal_mode(struct tok_state *tok, tokenizer_mode* current_tok, struct t
896896
(c == 'n' && lookahead(tok, "umerator")) ||
897897
(c == 'r' && lookahead(tok, "eal")))
898898
{
899+
if (_PyTokenizer_parser_warn(tok, PyExc_SyntaxWarning,
900+
"invalid float literal"))
901+
{
902+
return 0;
903+
}
899904
tok_backup(tok, c);
900905
c = '.';
901906
goto hexint;

0 commit comments

Comments
 (0)