bpo-45292: [PEP-654] add except* (GH-29581)

This commit is contained in:
Irit Katriel 2021-12-14 16:48:15 +00:00 committed by GitHub
parent 850aefc2c6
commit d60457a667
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
34 changed files with 7070 additions and 3332 deletions

View file

@ -1419,6 +1419,30 @@ class GrammarTests(unittest.TestCase):
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_try_star(self):
### try_stmt: 'try': suite (except_star_clause : suite) + ['else' ':' suite]
### except_star_clause: 'except*' expr ['as' NAME]
try:
1/0
except* ZeroDivisionError:
pass
else:
pass
try: 1/0
except* EOFError: pass
except* ZeroDivisionError as msg: pass
else: pass
try: 1/0
except* (EOFError, TypeError, ZeroDivisionError): pass
try: 1/0
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")
compile("try:\n pass\nexcept*:\n pass", "?", "exec")
def test_suite(self):
# simple_stmt | NEWLINE INDENT NEWLINE* (stmt NEWLINE*)+ DEDENT
if 1: pass