File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -52,6 +52,39 @@ def test_unused_typevar_pep695_switch_order(self):
5252 """ ,
5353 )
5454
55+ @test_utils .skipBeforePy ((3 , 12 ), "PEP 695 - 3.12 feature" )
56+ def test_unused_typevar_pep695_function_type_var_single (self ):
57+ ty = self .Infer ("""
58+ def foo[T, S](a: T) -> T:
59+ return a
60+ """ )
61+ self .assertTypesMatchPytd (
62+ ty ,
63+ """
64+ from typing import TypeVar
65+ T = TypeVar("T")
66+
67+ def foo(a: T) -> T: ...
68+ """ ,
69+ )
70+
71+ @test_utils .skipBeforePy ((3 , 12 ), "PEP 695 - 3.12 feature" )
72+ def test_unused_typevar_pep695_function_type_var_double (self ):
73+ ty = self .Infer ("""
74+ def foo[T, S](a: T, b: S) -> tuple[S, T]:
75+ return (a, b)
76+ """ )
77+ self .assertTypesMatchPytd (
78+ ty ,
79+ """
80+ from typing import TypeVar
81+ S = TypeVar('S')
82+ T = TypeVar('T')
83+
84+ def foo(a: T, b: S) -> tuple[S, T]: ...
85+ """ ,
86+ )
87+
5588 def test_import_typevar (self ):
5689 with test_utils .Tempdir () as d :
5790 d .create_file ("a.pyi" , """T = TypeVar("T")""" )
Original file line number Diff line number Diff line change @@ -3939,7 +3939,13 @@ def byte_INTRINSIC_TYPEVAR_WITH_CONSTRAINTS(self, state):
39393939 return state
39403940
39413941 def byte_INTRINSIC_SET_FUNCTION_TYPE_PARAMS (self , state ):
3942- # TODO: b/350910471 - Implement to support PEP 695
3942+ # Second parameter here is a type parameter, it's stored to the
3943+ # __type_params__ function attribute at runtime, but this information is not
3944+ # consumed by us. This intrinsic consumes two parameters which is the
3945+ # function object and the type parameter list and returns the function
3946+ # object.
3947+ state , (func , _ ) = state .popn (2 )
3948+ state = state .push (func )
39433949 return state
39443950
39453951
You can’t perform that action at this time.
0 commit comments