summaryrefslogtreecommitdiff
path: root/Lib/test/test_exceptions.py
diff options
context:
space:
mode:
authorLysandros Nikolaou <lisandrosnik@gmail.com>2020-05-13 22:36:27 +0300
committerGitHub <noreply@github.com>2020-05-13 20:36:27 +0100
commita15c9b3a0524e5ca0434d2ad11076677824af941 (patch)
treeab2089e87bee11e82d911d3471a8d39192e22139 /Lib/test/test_exceptions.py
parentde92769d473d1c0955d36da2fc71462621326f00 (diff)
downloadcpython-git-a15c9b3a0524e5ca0434d2ad11076677824af941.tar.gz
bpo-40334: Always show the caret on SyntaxErrors (GH-20050)
This commit fixes SyntaxError locations when the caret is not displayed, by doing the following: - `col_number` always gets set to the location of the offending node/expr. When no caret is to be displayed, this gets achieved by setting the object holding the error line to None. - Introduce a new function `_PyPegen_raise_error_known_location`, which can be called, when an arbitrary `lineno`/`col_offset` needs to be passed. This function then gets used in the grammar (through some new macros and inline functions) so that SyntaxError locations of the new parser match that of the old.
Diffstat (limited to 'Lib/test/test_exceptions.py')
-rw-r--r--Lib/test/test_exceptions.py15
1 files changed, 6 insertions, 9 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index dbd7fa6bdd..b689ec7aed 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -242,16 +242,13 @@ class ExceptionTests(unittest.TestCase):
check('from __future__ import doesnt_exist', 1, 1)
check('from __future__ import braces', 1, 1)
check('x=1\nfrom __future__ import division', 2, 1)
- check('(yield i) = 2', 1, 1)
+ check('foo(1=2)', 1, 5)
+ check('def f():\n x, y: int', 2, 3)
+ check('[*x for x in xs]', 1, 2)
+ check('foo(x for x in range(10), 100)', 1, 5)
+ check('(yield i) = 2', 1, 1 if support.use_old_parser() else 2)
check('def f(*):\n pass', 1, 7 if support.use_old_parser() else 8)
- check('foo(1=2)', 1, 5 if support.use_old_parser() else 6)
-
- @support.skip_if_new_parser("Pegen column offsets might be different")
- def testSyntaxErrorOffsetCustom(self):
- self.check('for 1 in []: pass', 1, 5)
- self.check('[*x for x in xs]', 1, 2)
- self.check('def f():\n x, y: int', 2, 3)
- self.check('foo(x for x in range(10), 100)', 1, 5)
+ check('for 1 in []: pass', 1, 5 if support.use_old_parser() else 7)
@cpython_only
def testSettingException(self):