44import unittest
55from test .support import requires_working_socket , check_syntax_error
66
7- from typing import Any , Generic , Sequence , TypeVar , TypeVarTuple , ParamSpec
7+ from typing import Any , Generic , Sequence , TypeVar , TypeVarTuple , ParamSpec , get_args
88
99
1010def run_code (code : str ) -> dict [str , Any ]:
@@ -144,8 +144,7 @@ def test_disallowed_expressions(self):
144144 check_syntax_error (self , "def f[T](y: (x := Sequence[T])): pass" )
145145
146146
147- class NonlocalTest (unittest .TestCase ):
148-
147+ class TypeParamsNonlocalTest (unittest .TestCase ):
149148 def test_nonlocal_disallowed_01 (self ):
150149 code = """
151150 def outer():
@@ -377,6 +376,21 @@ def meth[T](self, arg: int) -> T:
377376 c = Child ()
378377 self .assertEqual (c .meth (1 ), "basechild" )
379378
379+ def test_type_alias_containing_lambda (self ):
380+ type Alias [T ] = lambda : T
381+ T , = Alias .__type_params__
382+ self .assertIs (Alias .__value__ (), T )
383+
384+ def test_class_base_containing_lambda (self ):
385+ # Test that scopes nested inside hidden functions work correctly
386+ outer_var = "outer"
387+ class Base [T ]: ...
388+ class Child [T ](Base [lambda : (int , outer_var , T )]): ...
389+ base , _ = types .get_original_bases (Child )
390+ func , = get_args (base )
391+ T , = Child .__type_params__
392+ self .assertEqual (func (), (int , "outer" , T ))
393+
380394
381395def global_generic_func [T ]():
382396 pass
@@ -475,7 +489,7 @@ def foo[U: T](self): ...
475489 self .assertIs (X .Alias .__value__ , float )
476490
477491
478- class ManglingTest (unittest .TestCase ):
492+ class TypeParamsManglingTest (unittest .TestCase ):
479493 def test_mangling (self ):
480494 class Foo [__T ]:
481495 param = __T
@@ -498,7 +512,7 @@ def meth[__U](self, arg: __T, arg2: __U):
498512 self .assertEqual (Foo .Alias .__value__ , (T , V ))
499513
500514
501- class ComplexCallsTest (unittest .TestCase ):
515+ class TypeParamsComplexCallsTest (unittest .TestCase ):
502516 def test_defaults (self ):
503517 # Generic functions with both defaults and kwdefaults trigger a specific code path
504518 # in the compiler.
@@ -535,7 +549,7 @@ class C2[T](*bases, **kwargs):
535549 self .assertEqual (C2 .kwargs , {"c" : 3 })
536550
537551
538- class TypeParamsTraditionalTypeVars (unittest .TestCase ):
552+ class TypeParamsTraditionalTypeVarsTest (unittest .TestCase ):
539553 def test_traditional_01 (self ):
540554 code = """
541555 from typing import Generic
@@ -649,7 +663,7 @@ def func1[*A]():
649663 self .assertIsInstance (a , TypeVarTuple )
650664
651665
652- class TypeParamsTypeVarParamSpec (unittest .TestCase ):
666+ class TypeParamsTypeVarParamSpecTest (unittest .TestCase ):
653667 def test_paramspec_01 (self ):
654668 code = """def func1[**A: str](): pass"""
655669 check_syntax_error (self , code , "cannot use bound with ParamSpec" )
0 commit comments