File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -140,6 +140,26 @@ def test_bad_numerical_literals(self):
140140 check ("1e2_" , "invalid decimal literal" )
141141 check ("1e+" , "invalid decimal literal" )
142142
143+ def test_end_of_numerical_literals_offset (self ):
144+ # gh-149277: verify the error caret points at the first invalid
145+ # character, not the last valid digit.
146+ cases = [
147+ ("0xfg" , 4 ),
148+ ("0x9g" , 4 ),
149+ ("0b1z" , 4 ),
150+ ("0o7q" , 4 ),
151+ ("9spam" , 2 ),
152+ ("0xfspam" , 4 ),
153+ ("1.0x" , 4 ),
154+ ("1e3w" , 4 ),
155+ ("1jz" , 3 ),
156+ ]
157+ for source , expected_offset in cases :
158+ with self .subTest (source = source ):
159+ with self .assertRaises (SyntaxError ) as cm :
160+ compile (source , "<test>" , "eval" )
161+ self .assertEqual (cm .exception .offset , expected_offset )
162+
143163 def test_end_of_numerical_literals (self ):
144164 def check (test , error = False ):
145165 with self .subTest (expr = test ):
You can’t perform that action at this time.
0 commit comments