@@ -4858,7 +4858,7 @@ def f(x: X): ...
4858
4858
{'x' : list [list [ForwardRef ('X' )]]}
4859
4859
)
4860
4860
4861
- def test_pep695_generic_with_future_annotations (self ):
4861
+ def test_pep695_generic_class_with_future_annotations (self ):
4862
4862
original_globals = dict (ann_module695 .__dict__ )
4863
4863
4864
4864
hints_for_A = get_type_hints (ann_module695 .A )
@@ -4867,15 +4867,21 @@ def test_pep695_generic_with_future_annotations(self):
4867
4867
self .assertEqual (hints_for_A ["y" ].__args__ [0 ], Unpack [A_type_params [1 ]])
4868
4868
self .assertIs (hints_for_A ["z" ].__args__ [0 ], A_type_params [2 ])
4869
4869
4870
+ # should not have changed as a result of the get_type_hints() calls!
4871
+ self .assertEqual (ann_module695 .__dict__ , original_globals )
4872
+
4873
+ def test_pep695_generic_class_with_future_annotations_and_local_shadowing (self ):
4870
4874
hints_for_B = get_type_hints (ann_module695 .B )
4871
4875
self .assertEqual (hints_for_B , {"x" : int , "y" : str , "z" : bytes })
4872
4876
4877
+ def test_pep695_generic_class_with_future_annotations_name_clash_with_global_vars (self ):
4873
4878
hints_for_C = get_type_hints (ann_module695 .C )
4874
4879
self .assertEqual (
4875
4880
set (hints_for_C .values ()),
4876
4881
set (ann_module695 .C .__type_params__ )
4877
4882
)
4878
4883
4884
+ def test_pep_695_generic_function_with_future_annotations (self ):
4879
4885
hints_for_generic_function = get_type_hints (ann_module695 .generic_function )
4880
4886
func_t_params = ann_module695 .generic_function .__type_params__
4881
4887
self .assertEqual (
@@ -4886,6 +4892,13 @@ def test_pep695_generic_with_future_annotations(self):
4886
4892
self .assertIs (hints_for_generic_function ["z" ].__origin__ , func_t_params [2 ])
4887
4893
self .assertIs (hints_for_generic_function ["zz" ].__origin__ , func_t_params [2 ])
4888
4894
4895
+ def test_pep_695_generic_function_with_future_annotations_name_clash_with_global_vars (self ):
4896
+ self .assertEqual (
4897
+ set (get_type_hints (ann_module695 .generic_function_2 ).values ()),
4898
+ set (ann_module695 .generic_function_2 .__type_params__ )
4899
+ )
4900
+
4901
+ def test_pep_695_generic_method_with_future_annotations (self ):
4889
4902
hints_for_generic_method = get_type_hints (ann_module695 .D .generic_method )
4890
4903
params = {
4891
4904
param .__name__ : param
@@ -4896,8 +4909,36 @@ def test_pep695_generic_with_future_annotations(self):
4896
4909
{"x" : params ["Foo" ], "y" : params ["Bar" ], "return" : types .NoneType }
4897
4910
)
4898
4911
4899
- # should not have changed as a result of the get_type_hints() calls!
4900
- self .assertEqual (ann_module695 .__dict__ , original_globals )
4912
+ def test_pep_695_generic_method_with_future_annotations_name_clash_with_global_vars (self ):
4913
+ self .assertEqual (
4914
+ set (get_type_hints (ann_module695 .D .generic_method_2 ).values ()),
4915
+ set (ann_module695 .D .generic_method_2 .__type_params__ )
4916
+ )
4917
+
4918
+ def test_pep_695_generics_with_future_annotations_nested_in_function (self ):
4919
+ results = ann_module695 .nested ()
4920
+
4921
+ self .assertEqual (
4922
+ set (results .hints_for_E .values ()),
4923
+ set (results .E .__type_params__ )
4924
+ )
4925
+ self .assertEqual (
4926
+ set (results .hints_for_E_meth .values ()),
4927
+ set (results .E .generic_method .__type_params__ )
4928
+ )
4929
+ self .assertNotEqual (
4930
+ set (results .hints_for_E_meth .values ()),
4931
+ set (results .E .__type_params__ )
4932
+ )
4933
+ self .assertEqual (
4934
+ set (results .hints_for_E_meth .values ()).intersection (results .E .__type_params__ ),
4935
+ set ()
4936
+ )
4937
+
4938
+ self .assertEqual (
4939
+ set (results .hints_for_generic_func .values ()),
4940
+ set (results .generic_func .__type_params__ )
4941
+ )
4901
4942
4902
4943
def test_extended_generic_rules_subclassing (self ):
4903
4944
class T1 (Tuple [T , KT ]): ...
0 commit comments