diff options
author | 2021-01-31 22:52:56 +0000 | |
---|---|---|
committer | 2021-01-31 22:52:56 +0000 | |
commit | 835f14ff8eec10b3d96f821a1eb46a986e00c690 (patch) | |
tree | d514cc3cb32ed708ea584edd7c86726f6e581242 /Lib | |
parent | bpo-42986: Fix parser crash when reporting syntax errors in f-string with new... (diff) | |
download | cpython-835f14ff8eec10b3d96f821a1eb46a986e00c690.tar.gz cpython-835f14ff8eec10b3d96f821a1eb46a986e00c690.tar.bz2 cpython-835f14ff8eec10b3d96f821a1eb46a986e00c690.zip |
bpo-43017: Improve error message for unparenthesised tuples in comprehensions (GH24314)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_named_expressions.py | 3 | ||||
-rw-r--r-- | Lib/test/test_syntax.py | 15 |
2 files changed, 17 insertions, 1 deletions
diff --git a/Lib/test/test_named_expressions.py b/Lib/test/test_named_expressions.py index 5908f121085..20ac2e699f0 100644 --- a/Lib/test/test_named_expressions.py +++ b/Lib/test/test_named_expressions.py @@ -101,7 +101,8 @@ class NamedExpressionInvalidTest(unittest.TestCase): def test_named_expression_invalid_17(self): code = "[i := 0, j := 1 for i, j in [(1, 2), (3, 4)]]" - with self.assertRaisesRegex(SyntaxError, "invalid syntax"): + with self.assertRaisesRegex(SyntaxError, + "did you forget parentheses around the comprehension target?"): exec(code, {}, {}) def test_named_expression_invalid_in_class_body(self): diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py index c8d191df4cc..604474f1e83 100644 --- a/Lib/test/test_syntax.py +++ b/Lib/test/test_syntax.py @@ -235,6 +235,21 @@ SyntaxError: invalid syntax Traceback (most recent call last): SyntaxError: invalid syntax +Comprehensions creating tuples without parentheses +should produce a specialized error message: + +>>> [x,y for x,y in range(100)] +Traceback (most recent call last): +SyntaxError: did you forget parentheses around the comprehension target? + +>>> {x,y for x,y in range(100)} +Traceback (most recent call last): +SyntaxError: did you forget parentheses around the comprehension target? + +>>> {x,y: None for x,y in range(100)} +Traceback (most recent call last): +SyntaxError: did you forget parentheses around the comprehension target? + From compiler_complex_args(): >>> def f(None=1): |