summaryrefslogtreecommitdiff
path: root/Lib/test/test_syntax.py
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2021-12-14 16:48:15 +0000
committerGitHub <noreply@github.com>2021-12-14 16:48:15 +0000
commitd60457a6673cf0263213c2f2be02c633ec2e2038 (patch)
tree04461db9079cf30a98c5a4070098f795275aa910 /Lib/test/test_syntax.py
parent850aefc2c651110a784cd5478af9774b1f6287a3 (diff)
downloadcpython-git-d60457a6673cf0263213c2f2be02c633ec2e2038.tar.gz
bpo-45292: [PEP-654] add except* (GH-29581)
Diffstat (limited to 'Lib/test/test_syntax.py')
-rw-r--r--Lib/test/test_syntax.py100
1 files changed, 100 insertions, 0 deletions
diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py
index fc3c62954a..6286529d27 100644
--- a/Lib/test/test_syntax.py
+++ b/Lib/test/test_syntax.py
@@ -955,6 +955,48 @@ Custom error messages for try blocks that are not followed by except/finally
Traceback (most recent call last):
SyntaxError: expected 'except' or 'finally' block
+Custom error message for try block mixing except and except*
+
+ >>> try:
+ ... pass
+ ... except TypeError:
+ ... pass
+ ... except* ValueError:
+ ... pass
+ Traceback (most recent call last):
+ SyntaxError: cannot have both 'except' and 'except*' on the same 'try'
+
+ >>> try:
+ ... pass
+ ... except* TypeError:
+ ... pass
+ ... except ValueError:
+ ... pass
+ Traceback (most recent call last):
+ SyntaxError: cannot have both 'except' and 'except*' on the same 'try'
+
+ >>> try:
+ ... pass
+ ... except TypeError:
+ ... pass
+ ... except TypeError:
+ ... pass
+ ... except* ValueError:
+ ... pass
+ Traceback (most recent call last):
+ SyntaxError: cannot have both 'except' and 'except*' on the same 'try'
+
+ >>> try:
+ ... pass
+ ... except* TypeError:
+ ... pass
+ ... except* TypeError:
+ ... pass
+ ... except ValueError:
+ ... pass
+ Traceback (most recent call last):
+ SyntaxError: cannot have both 'except' and 'except*' on the same 'try'
+
Ensure that early = are not matched by the parser as invalid comparisons
>>> f(2, 4, x=34); 1 $ 2
Traceback (most recent call last):
@@ -1070,6 +1112,13 @@ Specialized indentation errors:
>>> try:
... something()
+ ... except* A:
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after 'except*' statement on line 3
+
+ >>> try:
+ ... something()
... except A:
... pass
... finally:
@@ -1077,6 +1126,15 @@ Specialized indentation errors:
Traceback (most recent call last):
IndentationError: expected an indented block after 'finally' statement on line 5
+ >>> try:
+ ... something()
+ ... except* A:
+ ... pass
+ ... finally:
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after 'finally' statement on line 5
+
>>> with A:
... pass
Traceback (most recent call last):
@@ -1180,6 +1238,48 @@ raise a custom exception
SyntaxError: multiple exception types must be parenthesized
+ >>> try:
+ ... pass
+ ... except* A, B:
+ ... pass
+ Traceback (most recent call last):
+ SyntaxError: multiple exception types must be parenthesized
+
+ >>> try:
+ ... pass
+ ... except* A, B, C:
+ ... pass
+ Traceback (most recent call last):
+ SyntaxError: multiple exception types must be parenthesized
+
+ >>> try:
+ ... pass
+ ... except* A, B, C as blech:
+ ... pass
+ Traceback (most recent call last):
+ SyntaxError: multiple exception types must be parenthesized
+
+ >>> try:
+ ... pass
+ ... except* A, B, C as blech:
+ ... pass
+ ... finally:
+ ... pass
+ Traceback (most recent call last):
+ SyntaxError: multiple exception types must be parenthesized
+
+Custom exception for 'except*' without an exception type
+
+ >>> try:
+ ... pass
+ ... except* A as a:
+ ... pass
+ ... except*:
+ ... pass
+ Traceback (most recent call last):
+ SyntaxError: expected one or more exception types
+
+
>>> f(a=23, a=234)
Traceback (most recent call last):
...