aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_symtable.py12
-rw-r--r--Lib/test/test_syntax.py100
2 files changed, 107 insertions, 5 deletions
diff --git a/Lib/test/test_symtable.py b/Lib/test/test_symtable.py
index 903c6d66f50..175f453447b 100644
--- a/Lib/test/test_symtable.py
+++ b/Lib/test/test_symtable.py
@@ -49,7 +49,7 @@ type GenericAlias[T] = list[T]
def generic_spam[T](a):
pass
-class GenericMine[T: int]:
+class GenericMine[T: int, U: (int, str) = int]:
pass
"""
@@ -78,6 +78,7 @@ class SymtableTest(unittest.TestCase):
GenericMine = find_block(top, "GenericMine")
GenericMine_inner = find_block(GenericMine, "GenericMine")
T = find_block(GenericMine, "T")
+ U = find_block(GenericMine, "U")
def test_type(self):
self.assertEqual(self.top.get_type(), "module")
@@ -87,13 +88,14 @@ class SymtableTest(unittest.TestCase):
self.assertEqual(self.internal.get_type(), "function")
self.assertEqual(self.foo.get_type(), "function")
self.assertEqual(self.Alias.get_type(), "type alias")
- self.assertEqual(self.GenericAlias.get_type(), "type parameter")
+ self.assertEqual(self.GenericAlias.get_type(), "type parameters")
self.assertEqual(self.GenericAlias_inner.get_type(), "type alias")
- self.assertEqual(self.generic_spam.get_type(), "type parameter")
+ self.assertEqual(self.generic_spam.get_type(), "type parameters")
self.assertEqual(self.generic_spam_inner.get_type(), "function")
- self.assertEqual(self.GenericMine.get_type(), "type parameter")
+ self.assertEqual(self.GenericMine.get_type(), "type parameters")
self.assertEqual(self.GenericMine_inner.get_type(), "class")
- self.assertEqual(self.T.get_type(), "TypeVar bound")
+ self.assertEqual(self.T.get_type(), "type variable")
+ self.assertEqual(self.U.get_type(), "type variable")
def test_id(self):
self.assertGreater(self.top.get_id(), 0)
diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py
index 491f7fd7908..cdeb26adf34 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):
...