summaryrefslogtreecommitdiff
path: root/Lib/test/test_peg_parser.py
diff options
context:
space:
mode:
authorLysandros Nikolaou <lisandrosnik@gmail.com>2020-05-14 23:13:50 +0300
committerGitHub <noreply@github.com>2020-05-14 21:13:50 +0100
commitce21cfca7bb2d18921bc4ac27cb064726996c519 (patch)
tree04a1dad07cbb70619149b3dc867b515ed64b62f5 /Lib/test/test_peg_parser.py
parentbcc30360951a303aa72b0502b77aad2c5f09f30d (diff)
downloadcpython-git-ce21cfca7bb2d18921bc4ac27cb064726996c519.tar.gz
bpo-40618: Disallow invalid targets in augassign and except clauses (GH-20083)
This commit fixes the new parser to disallow invalid targets in the following scenarios: - Augmented assignments must only accept a single target (Name, Attribute or Subscript), but no tuples or lists. - `except` clauses should only accept a single `Name` as a target. Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
Diffstat (limited to 'Lib/test/test_peg_parser.py')
-rw-r--r--Lib/test/test_peg_parser.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_peg_parser.py b/Lib/test/test_peg_parser.py
index df2d46d882..71e071940d 100644
--- a/Lib/test/test_peg_parser.py
+++ b/Lib/test/test_peg_parser.py
@@ -35,6 +35,9 @@ TEST_CASES = [
('attribute_simple', 'a.b'),
('attributes_subscript', 'a.b[0]'),
('augmented_assignment', 'x += 42'),
+ ('augmented_assignment_attribute', 'a.b.c += 42'),
+ ('augmented_assignment_paren', '(x) += 42'),
+ ('augmented_assignment_paren_subscript', '(x[0]) -= 42'),
('binop_add', '1 + 1'),
('binop_add_multiple', '1 + 1 + 1 + 1'),
('binop_all', '1 + 2 * 5 + 3 ** 2 - -3'),
@@ -547,6 +550,11 @@ TEST_CASES = [
with a as (x, y):
pass
'''),
+ ('with_list_target',
+ '''
+ with a as [x, y]:
+ pass
+ '''),
('yield', 'yield'),
('yield_expr', 'yield a'),
('yield_from', 'yield from a'),
@@ -560,6 +568,9 @@ FAIL_TEST_CASES = [
("annotation_tuple", "(a,): int"),
("annotation_tuple_without_paren", "a,: int"),
("assignment_keyword", "a = if"),
+ ("augmented_assignment_list", "[a, b] += 1"),
+ ("augmented_assignment_tuple", "a, b += 1"),
+ ("augmented_assignment_tuple_paren", "(a, b) += (1, 2)"),
("comprehension_lambda", "(a for a in lambda: b)"),
("comprehension_else", "(a for a in b if c else d"),
("del_call", "del a()"),
@@ -589,6 +600,20 @@ FAIL_TEST_CASES = [
a
"""),
("not_terminated_string", "a = 'example"),
+ ("try_except_attribute_target",
+ """
+ try:
+ pass
+ except Exception as a.b:
+ pass
+ """),
+ ("try_except_subscript_target",
+ """
+ try:
+ pass
+ except Exception as a[0]:
+ pass
+ """),
]
FAIL_SPECIALIZED_MESSAGE_CASES = [