Skip to content

Commit 1d0c6c5

Browse files
committed
As it's requires a PEP, lets yrigger a syntax warning
1 parent ca0a28d commit 1d0c6c5

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

Lib/test/test_grammar.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ def test_plain_integers(self):
181181
def test_attrs_on_hexintegers(self):
182182
good_meth = [m for m in dir(int) if not m.startswith('_')]
183183
for m in good_meth:
184-
self.assertEqual(eval('0x1.' + m), eval('(0x1).' + m))
184+
with self.assertWarns(SyntaxWarning):
185+
v = eval('0x1.' + m)
186+
self.assertEqual(v, eval('(0x1).' + m))
185187
self.check_syntax_error('0x1.spam', "invalid hexadecimal literal",
186188
lineno=1, offset=4)
187189
self.check_syntax_error('0x1.foo', "invalid hexadecimal literal",

Parser/lexer/lexer.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,11 @@ tok_get_normal_mode(struct tok_state *tok, tokenizer_mode* current_tok, struct t
793793
(c == 'n' && lookahead(tok, "umerator")) ||
794794
(c == 'r' && lookahead(tok, "eal")))
795795
{
796+
if (_PyTokenizer_parser_warn(tok, PyExc_SyntaxWarning,
797+
"invalid float literal"))
798+
{
799+
return 0;
800+
}
796801
tok_backup(tok, c);
797802
c = '.';
798803
goto hexint;

0 commit comments

Comments
 (0)