summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_grammar.py
diff options
context:
space:
mode:
authorLysandros Nikolaou <lisandrosnik@gmail.com>2020-05-14 20:13:50 (GMT)
committerGitHub <noreply@github.com>2020-05-14 20:13:50 (GMT)
commitce21cfca7bb2d18921bc4ac27cb064726996c519 (patch)
tree04a1dad07cbb70619149b3dc867b515ed64b62f5 /Lib/test/test_grammar.py
parentbcc30360951a303aa72b0502b77aad2c5f09f30d (diff)
downloadcpython-ce21cfca7bb2d18921bc4ac27cb064726996c519.zip
cpython-ce21cfca7bb2d18921bc4ac27cb064726996c519.tar.gz
cpython-ce21cfca7bb2d18921bc4ac27cb064726996c519.tar.bz2
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_grammar.py')
-rw-r--r--Lib/test/test_grammar.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py
index 02ba8a8..e1a402e 100644
--- a/Lib/test/test_grammar.py
+++ b/Lib/test/test_grammar.py
@@ -1279,7 +1279,7 @@ class GrammarTests(unittest.TestCase):
def test_try(self):
### try_stmt: 'try' ':' suite (except_clause ':' suite)+ ['else' ':' suite]
### | 'try' ':' suite 'finally' ':' suite
- ### except_clause: 'except' [expr ['as' expr]]
+ ### except_clause: 'except' [expr ['as' NAME]]
try:
1/0
except ZeroDivisionError:
@@ -1297,6 +1297,9 @@ class GrammarTests(unittest.TestCase):
except (EOFError, TypeError, ZeroDivisionError) as msg: pass
try: pass
finally: pass
+ with self.assertRaises(SyntaxError):
+ compile("try:\n pass\nexcept Exception as a.b:\n pass", "?", "exec")
+ compile("try:\n pass\nexcept Exception as a[b]:\n pass", "?", "exec")
def test_suite(self):
# simple_stmt | NEWLINE INDENT NEWLINE* (stmt NEWLINE*)+ DEDENT