mirror of
https://github.com/python/cpython.git
synced 2025-08-30 13:38:43 +00:00
bpo-34683: Make SyntaxError column offsets consistently 1-indexed (gh-9338)
Also point to start of tokens in parsing errors. Fixes bpo-34683
This commit is contained in:
parent
223e501fb9
commit
025eb98dc0
11 changed files with 65 additions and 21 deletions
|
@ -187,6 +187,45 @@ class ExceptionTests(unittest.TestCase):
|
|||
check('def spam():\n print(1)\n print(2)', 3, 10)
|
||||
check('Python = "Python" +', 1, 20)
|
||||
check('Python = "\u1e54\xfd\u0163\u0125\xf2\xf1" +', 1, 20)
|
||||
check('x = "a', 1, 7)
|
||||
check('lambda x: x = 2', 1, 1)
|
||||
|
||||
# Errors thrown by compile.c
|
||||
check('class foo:return 1', 1, 11)
|
||||
check('def f():\n continue', 2, 3)
|
||||
check('def f():\n break', 2, 3)
|
||||
check('try:\n pass\nexcept:\n pass\nexcept ValueError:\n pass', 2, 3)
|
||||
|
||||
# Errors thrown by tokenizer.c
|
||||
check('(0x+1)', 1, 3)
|
||||
check('x = 0xI', 1, 6)
|
||||
check('0010 + 2', 1, 4)
|
||||
check('x = 32e-+4', 1, 8)
|
||||
check('x = 0o9', 1, 6)
|
||||
|
||||
# Errors thrown by symtable.c
|
||||
check('x = [(yield i) for i in range(3)]', 1, 6)
|
||||
check('def f():\n from _ import *', 1, 1)
|
||||
check('def f(x, x):\n pass', 1, 1)
|
||||
check('def f(x):\n nonlocal x', 2, 3)
|
||||
check('def f(x):\n x = 1\n global x', 3, 3)
|
||||
check('nonlocal x', 1, 1)
|
||||
check('def f():\n global x\n nonlocal x', 2, 3)
|
||||
|
||||
# Errors thrown by ast.c
|
||||
check('for 1 in []: pass', 1, 5)
|
||||
check('def f(*):\n pass', 1, 7)
|
||||
check('[*x for x in xs]', 1, 2)
|
||||
check('def f():\n x, y: int', 2, 3)
|
||||
check('(yield i) = 2', 1, 1)
|
||||
check('foo(x for x in range(10), 100)', 1, 5)
|
||||
check('foo(1=2)', 1, 5)
|
||||
|
||||
# Errors thrown by future.c
|
||||
check('from __future__ import doesnt_exist', 1, 1)
|
||||
check('from __future__ import braces', 1, 1)
|
||||
check('x=1\nfrom __future__ import division', 2, 1)
|
||||
|
||||
|
||||
@cpython_only
|
||||
def testSettingException(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue