diff options
author | Ammar Askar <ammar_askar@hotmail.com> | 2018-09-24 21:12:49 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2018-09-24 21:12:49 (GMT) |
commit | 025eb98dc0c1dc27404df6c544fc2944e0fa9f3a (patch) | |
tree | ad93cb6963abd43430766fa85b629b2d5896889b /Lib/test/test_exceptions.py | |
parent | 223e501fb9c2b6ae21b96054e20c4c31d94a5d96 (diff) | |
download | cpython-025eb98dc0c1dc27404df6c544fc2944e0fa9f3a.zip cpython-025eb98dc0c1dc27404df6c544fc2944e0fa9f3a.tar.gz cpython-025eb98dc0c1dc27404df6c544fc2944e0fa9f3a.tar.bz2 |
bpo-34683: Make SyntaxError column offsets consistently 1-indexed (gh-9338)
Also point to start of tokens in parsing errors.
Fixes bpo-34683
Diffstat (limited to 'Lib/test/test_exceptions.py')
-rw-r--r-- | Lib/test/test_exceptions.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index 2a9ec70..5353248 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -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): |