8
8
from annotationlib import Format , ForwardRef , get_annotations , get_annotate_function
9
9
from typing import Unpack
10
10
11
+ from test import support
11
12
from test .test_inspect import inspect_stock_annotations
12
13
from test .test_inspect import inspect_stringized_annotations
13
14
from test .test_inspect import inspect_stringized_annotations_2
@@ -327,7 +328,9 @@ class C1(metaclass=NoDict):
327
328
)
328
329
self .assertEqual (annotationlib .get_annotations (NoDict ), {"b" : str })
329
330
self .assertEqual (
330
- annotationlib .get_annotations (NoDict , format = annotationlib .Format .FORWARDREF ),
331
+ annotationlib .get_annotations (
332
+ NoDict , format = annotationlib .Format .FORWARDREF
333
+ ),
331
334
{"b" : str },
332
335
)
333
336
self .assertEqual(
@@ -715,12 +718,13 @@ def test_pep695_generic_class_with_future_annotations_and_local_shadowing(self):
715
718
)
716
719
self .assertEqual (B_annotations , {"x" : int , "y" : str , "z" : bytes })
717
720
718
- def test_pep695_generic_class_with_future_annotations_name_clash_with_global_vars (self ):
721
+ def test_pep695_generic_class_with_future_annotations_name_clash_with_global_vars (
722
+ self ,
723
+ ):
719
724
ann_module695 = inspect_stringized_annotations_pep695
720
725
C_annotations = annotationlib .get_annotations (ann_module695 .C , eval_str = True )
721
726
self .assertEqual (
722
- set (C_annotations .values ()),
723
- set (ann_module695 .C .__type_params__ )
727
+ set (C_annotations .values ()), set (ann_module695 .C .__type_params__ )
724
728
)
725
729
726
730
def test_pep_695_generic_function_with_future_annotations (self ):
@@ -737,17 +741,19 @@ def test_pep_695_generic_function_with_future_annotations(self):
737
741
self .assertIs (generic_func_annotations ["z" ].__origin__ , func_t_params [2 ])
738
742
self .assertIs (generic_func_annotations ["zz" ].__origin__ , func_t_params [2 ])
739
743
740
- def test_pep_695_generic_function_with_future_annotations_name_clash_with_global_vars (self ):
744
+ def test_pep_695_generic_function_with_future_annotations_name_clash_with_global_vars (
745
+ self ,
746
+ ):
741
747
self .assertEqual (
742
748
set (
743
749
annotationlib .get_annotations (
744
750
inspect_stringized_annotations_pep695 .generic_function_2 ,
745
- eval_str = True
751
+ eval_str = True ,
746
752
).values ()
747
753
),
748
754
set (
749
755
inspect_stringized_annotations_pep695 .generic_function_2 .__type_params__
750
- )
756
+ ),
751
757
)
752
758
753
759
def test_pep_695_generic_method_with_future_annotations (self ):
@@ -761,23 +767,27 @@ def test_pep_695_generic_method_with_future_annotations(self):
761
767
}
762
768
self .assertEqual (
763
769
generic_method_annotations ,
764
- {"x" : params ["Foo" ], "y" : params ["Bar" ], "return" : None }
770
+ {"x" : params ["Foo" ], "y" : params ["Bar" ], "return" : None },
765
771
)
766
772
767
- def test_pep_695_generic_method_with_future_annotations_name_clash_with_global_vars (self ):
773
+ def test_pep_695_generic_method_with_future_annotations_name_clash_with_global_vars (
774
+ self ,
775
+ ):
768
776
self .assertEqual (
769
777
set (
770
778
annotationlib .get_annotations (
771
779
inspect_stringized_annotations_pep695 .D .generic_method_2 ,
772
- eval_str = True
780
+ eval_str = True ,
773
781
).values ()
774
782
),
775
783
set (
776
784
inspect_stringized_annotations_pep695 .D .generic_method_2 .__type_params__
777
- )
785
+ ),
778
786
)
779
787
780
- def test_pep_695_generic_method_with_future_annotations_name_clash_with_global_and_local_vars (self ):
788
+ def test_pep_695_generic_method_with_future_annotations_name_clash_with_global_and_local_vars (
789
+ self ,
790
+ ):
781
791
self .assertEqual (
782
792
annotationlib .get_annotations (
783
793
inspect_stringized_annotations_pep695 .E , eval_str = True
@@ -789,20 +799,20 @@ def test_pep_695_generics_with_future_annotations_nested_in_function(self):
789
799
results = inspect_stringized_annotations_pep695 .nested ()
790
800
791
801
self .assertEqual (
792
- set (results .F_annotations .values ()),
793
- set (results .F .__type_params__ )
802
+ set (results .F_annotations .values ()), set (results .F .__type_params__ )
794
803
)
795
804
self .assertEqual (
796
805
set (results .F_meth_annotations .values ()),
797
- set (results .F .generic_method .__type_params__ )
806
+ set (results .F .generic_method .__type_params__ ),
798
807
)
799
808
self .assertNotEqual (
800
- set (results .F_meth_annotations .values ()),
801
- set (results .F .__type_params__ )
809
+ set (results .F_meth_annotations .values ()), set (results .F .__type_params__ )
802
810
)
803
811
self .assertEqual (
804
- set (results .F_meth_annotations .values ()).intersection (results .F .__type_params__ ),
805
- set ()
812
+ set (results .F_meth_annotations .values ()).intersection (
813
+ results .F .__type_params__
814
+ ),
815
+ set (),
806
816
)
807
817
808
818
self .assertEqual (results .G_annotations , {"x" : str })
@@ -823,7 +833,9 @@ def evaluate(format, exc=NotImplementedError):
823
833
with self .assertRaises (NameError ):
824
834
annotationlib .call_evaluate_function (evaluate , annotationlib .Format .VALUE )
825
835
self .assertEqual (
826
- annotationlib .call_evaluate_function (evaluate , annotationlib .Format .FORWARDREF ),
836
+ annotationlib .call_evaluate_function (
837
+ evaluate , annotationlib .Format .FORWARDREF
838
+ ),
827
839
annotationlib .ForwardRef ("undefined" ),
828
840
)
829
841
self .assertEqual (
@@ -853,12 +865,14 @@ class Y(metaclass=Meta):
853
865
self .assertEqual (get_annotate_function (Y )(Format .VALUE ), {"b" : float })
854
866
855
867
def test_unannotated_meta (self ):
856
- class Meta (type ): pass
868
+ class Meta (type ):
869
+ pass
857
870
858
871
class X (metaclass = Meta ):
859
872
a : str
860
873
861
- class Y (X ): pass
874
+ class Y (X ):
875
+ pass
862
876
863
877
self .assertEqual (get_annotations (Meta ), {})
864
878
self .assertIs (get_annotate_function (Meta ), None )
@@ -907,6 +921,13 @@ class D(metaclass=Meta):
907
921
self .assertEqual (get_annotations (c ), c .expected_annotations )
908
922
annotate_func = get_annotate_function (c )
909
923
if c .expected_annotations :
910
- self .assertEqual (annotate_func (Format .VALUE ), c .expected_annotations )
924
+ self .assertEqual (
925
+ annotate_func (Format .VALUE ), c .expected_annotations
926
+ )
911
927
else :
912
928
self .assertIs (annotate_func , None )
929
+
930
+
931
+ class TestAnnotationLib (unittest .TestCase ):
932
+ def test__all__ (self ):
933
+ support .check__all__ (self , annotationlib )
0 commit comments