summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorLysandros Nikolaou <lisandrosnik@gmail.com>2020-05-04 10:58:31 (GMT)
committerGitHub <noreply@github.com>2020-05-04 10:58:31 (GMT)
commite10e7c771bf06112c4a311e0ef6b8af6423b0cca (patch)
tree79a34dfffd7b555dcab60db13ad4ab678d4b9068 /Lib
parentc3f001461d5794c81cf5f70e08ae5435fe935ceb (diff)
downloadcpython-e10e7c771bf06112c4a311e0ef6b8af6423b0cca.zip
cpython-e10e7c771bf06112c4a311e0ef6b8af6423b0cca.tar.gz
cpython-e10e7c771bf06112c4a311e0ef6b8af6423b0cca.tar.bz2
bpo-40334: Spacialized error message for invalid args after bare '*' (GH-19865)
When parsing things like `def f(*): pass` the old parser used to output `SyntaxError: named arguments must follow bare *`, which the new parser wasn't able to do.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_exceptions.py2
-rw-r--r--Lib/test/test_peg_parser.py6
-rw-r--r--Lib/test/test_syntax.py6
3 files changed, 10 insertions, 4 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index 354b3f4..d83b73a 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -242,11 +242,11 @@ 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('def f(*):\n pass', 1, 7 if support.use_old_parser() else 8)
@support.skip_if_new_parser("Pegen column offsets might be different")
def testSyntaxErrorOffsetCustom(self):
self.check('for 1 in []: pass', 1, 5)
- self.check('def f(*):\n pass', 1, 7)
self.check('[*x for x in xs]', 1, 2)
self.check('def f():\n x, y: int', 2, 3)
self.check('(yield i) = 2', 1, 1)
diff --git a/Lib/test/test_peg_parser.py b/Lib/test/test_peg_parser.py
index 1914944..d6939fd 100644
--- a/Lib/test/test_peg_parser.py
+++ b/Lib/test/test_peg_parser.py
@@ -603,6 +603,12 @@ FAIL_SPECIALIZED_MESSAGE_CASES = [
("1 += 1", "cannot assign to literal"),
("pass\n pass", "unexpected indent"),
("def f():\npass", "expected an indented block"),
+ ("def f(*): pass", "named arguments must follow bare *"),
+ ("def f(*,): pass", "named arguments must follow bare *"),
+ ("def f(*, **a): pass", "named arguments must follow bare *"),
+ ("lambda *: pass", "named arguments must follow bare *"),
+ ("lambda *,: pass", "named arguments must follow bare *"),
+ ("lambda *, **a: pass", "named arguments must follow bare *"),
]
GOOD_BUT_FAIL_TEST_CASES = [
diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py
index e7468ca..0c0fc48 100644
--- a/Lib/test/test_syntax.py
+++ b/Lib/test/test_syntax.py
@@ -627,9 +627,9 @@ Corner-cases that used to fail to raise the correct error:
Traceback (most recent call last):
SyntaxError: cannot assign to __debug__
- # >>> with (lambda *:0): pass
- # Traceback (most recent call last):
- # SyntaxError: named arguments must follow bare *
+ >>> with (lambda *:0): pass
+ Traceback (most recent call last):
+ SyntaxError: named arguments must follow bare *
Corner-cases that used to crash: