diff options
| author | Lysandros Nikolaou <lisandrosnik@gmail.com> | 2020-05-07 10:44:06 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-05-07 10:44:06 (GMT) |
| commit | 4638c6429575bd6de26b12b2af5df74d6568b553 (patch) | |
| tree | db027fceca158090caf8f194fc577d6631f82daa /Lib | |
| parent | 2f37c355ab0e9ec9c1753985d27c41fa0bd719b9 (diff) | |
| download | cpython-4638c6429575bd6de26b12b2af5df74d6568b553.zip cpython-4638c6429575bd6de26b12b2af5df74d6568b553.tar.gz cpython-4638c6429575bd6de26b12b2af5df74d6568b553.tar.bz2 | |
bpo-40334: Error message for invalid default args in function call (GH-19973)
When parsing something like `f(g()=2)`, where the name of a default arg
is not a NAME, but an arbitrary expression, a specialised error message
is emitted.
Diffstat (limited to 'Lib')
| -rw-r--r-- | Lib/test/test_exceptions.py | 4 | ||||
| -rw-r--r-- | Lib/test/test_peg_parser.py | 3 |
2 files changed, 5 insertions, 2 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index d83b73a..dbd7fa6 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -242,16 +242,16 @@ 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('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('(yield i) = 2', 1, 1) self.check('foo(x for x in range(10), 100)', 1, 5) - self.check('foo(1=2)', 1, 5) @cpython_only def testSettingException(self): diff --git a/Lib/test/test_peg_parser.py b/Lib/test/test_peg_parser.py index d6939fd..df2d46d 100644 --- a/Lib/test/test_peg_parser.py +++ b/Lib/test/test_peg_parser.py @@ -609,6 +609,9 @@ FAIL_SPECIALIZED_MESSAGE_CASES = [ ("lambda *: pass", "named arguments must follow bare *"), ("lambda *,: pass", "named arguments must follow bare *"), ("lambda *, **a: pass", "named arguments must follow bare *"), + ("f(g()=2", "expression cannot contain assignment, perhaps you meant \"==\"?"), + ("f(a, b, *c, d.e=2", "expression cannot contain assignment, perhaps you meant \"==\"?"), + ("f(*a, **b, c=0, d[1]=3)", "expression cannot contain assignment, perhaps you meant \"==\"?"), ] GOOD_BUT_FAIL_TEST_CASES = [ |
