summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_syntax.py
diff options
context:
space:
mode:
authorJelle Zijlstra <jelle.zijlstra@gmail.com>2024-06-17 15:01:49 (GMT)
committerGitHub <noreply@github.com>2024-06-17 15:01:49 (GMT)
commit7c47f93dff878bdc43f5162dd878cbb375711570 (patch)
tree7b02b412d2bc0f718d9df2912fa0b6cd66205de1 /Lib/test/test_syntax.py
parent03b89e3a3d155a06827f58d51238a731d8800cc9 (diff)
downloadcpython-7c47f93dff878bdc43f5162dd878cbb375711570.zip
cpython-7c47f93dff878bdc43f5162dd878cbb375711570.tar.gz
cpython-7c47f93dff878bdc43f5162dd878cbb375711570.tar.bz2
[3.13] gh-119933: Improve ``SyntaxError`` message for invalid type parameters expressions (GH-119976) (#120641)
(cherry picked from commit 4bf17c381fb7b465f0f26aecb94a6c54cf9be2d3) Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
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 491f7fd..cdeb26a 100644
--- a/Lib/test/test_syntax.py
+++ b/Lib/test/test_syntax.py
@@ -2046,16 +2046,91 @@ Invalid expressions in type scopes:
...
SyntaxError: Type parameter list cannot be empty
+ >>> def f[T: (x:=3)](): pass
+ Traceback (most recent call last):
+ ...
+ SyntaxError: named expression cannot be used within a TypeVar bound
+
+ >>> def f[T: ((x:= 3), int)](): pass
+ Traceback (most recent call last):
+ ...
+ SyntaxError: named expression cannot be used within a TypeVar constraint
+
+ >>> def f[T = ((x:=3))](): pass
+ Traceback (most recent call last):
+ ...
+ SyntaxError: named expression cannot be used within a TypeVar default
+
+ >>> async def f[T: (x:=3)](): pass
+ Traceback (most recent call last):
+ ...
+ SyntaxError: named expression cannot be used within a TypeVar bound
+
+ >>> async def f[T: ((x:= 3), int)](): pass
+ Traceback (most recent call last):
+ ...
+ SyntaxError: named expression cannot be used within a TypeVar constraint
+
+ >>> async def f[T = ((x:=3))](): pass
+ Traceback (most recent call last):
+ ...
+ SyntaxError: named expression cannot be used within a TypeVar default
+
>>> type A[T: (x:=3)] = int
Traceback (most recent call last):
...
SyntaxError: named expression cannot be used within a TypeVar bound
+ >>> type A[T: ((x:= 3), int)] = int
+ Traceback (most recent call last):
+ ...
+ SyntaxError: named expression cannot be used within a TypeVar constraint
+
+ >>> type A[T = ((x:=3))] = int
+ Traceback (most recent call last):
+ ...
+ SyntaxError: named expression cannot be used within a TypeVar default
+
+ >>> def f[T: (yield)](): pass
+ Traceback (most recent call last):
+ ...
+ SyntaxError: yield expression cannot be used within a TypeVar bound
+
+ >>> def f[T: (int, (yield))](): pass
+ Traceback (most recent call last):
+ ...
+ SyntaxError: yield expression cannot be used within a TypeVar constraint
+
+ >>> def f[T = (yield)](): pass
+ Traceback (most recent call last):
+ ...
+ SyntaxError: yield expression cannot be used within a TypeVar default
+
+ >>> def f[*Ts = (yield)](): pass
+ Traceback (most recent call last):
+ ...
+ SyntaxError: yield expression cannot be used within a TypeVarTuple default
+
+ >>> def f[**P = [(yield), int]](): pass
+ Traceback (most recent call last):
+ ...
+ SyntaxError: yield expression cannot be used within a ParamSpec default
+
>>> type A[T: (yield 3)] = int
Traceback (most recent call last):
...
SyntaxError: yield expression cannot be used within a TypeVar bound
+ >>> type A[T: (int, (yield 3))] = int
+ Traceback (most recent call last):
+ ...
+ SyntaxError: yield expression cannot be used within a TypeVar constraint
+
+ >>> type A[T = (yield 3)] = int
+ Traceback (most recent call last):
+ ...
+ SyntaxError: yield expression cannot be used within a TypeVar default
+
>>> type A[T: (await 3)] = int
Traceback (most recent call last):
...
@@ -2066,6 +2141,31 @@ Invalid expressions in type scopes:
...
SyntaxError: yield expression cannot be used within a TypeVar bound
+ >>> class A[T: (yield 3)]: pass
+ Traceback (most recent call last):
+ ...
+ SyntaxError: yield expression cannot be used within a TypeVar bound
+
+ >>> class A[T: (int, (yield 3))]: pass
+ Traceback (most recent call last):
+ ...
+ SyntaxError: yield expression cannot be used within a TypeVar constraint
+
+ >>> class A[T = (yield)]: pass
+ Traceback (most recent call last):
+ ...
+ SyntaxError: yield expression cannot be used within a TypeVar default
+
+ >>> class A[*Ts = (yield)]: pass
+ Traceback (most recent call last):
+ ...
+ SyntaxError: yield expression cannot be used within a TypeVarTuple default
+
+ >>> class A[**P = [(yield), int]]: pass
+ Traceback (most recent call last):
+ ...
+ SyntaxError: yield expression cannot be used within a ParamSpec default
+
>>> type A = (x := 3)
Traceback (most recent call last):
...