88from annotationlib import Format , ForwardRef , get_annotations , get_annotate_function
99from typing import Unpack
1010
11+ from test import support
1112from test .test_inspect import inspect_stock_annotations
1213from test .test_inspect import inspect_stringized_annotations
1314from test .test_inspect import inspect_stringized_annotations_2
@@ -327,7 +328,9 @@ class C1(metaclass=NoDict):
327328 )
328329 self .assertEqual (annotationlib .get_annotations (NoDict ), {"b" : str })
329330 self .assertEqual (
330- annotationlib .get_annotations (NoDict , format = annotationlib .Format .FORWARDREF ),
331+ annotationlib .get_annotations (
332+ NoDict , format = annotationlib .Format .FORWARDREF
333+ ),
331334 {"b" : str },
332335 )
333336 self .assertEqual (
@@ -715,12 +718,13 @@ def test_pep695_generic_class_with_future_annotations_and_local_shadowing(self):
715718 )
716719 self .assertEqual (B_annotations , {"x" : int , "y" : str , "z" : bytes })
717720
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+ ):
719724 ann_module695 = inspect_stringized_annotations_pep695
720725 C_annotations = annotationlib .get_annotations (ann_module695 .C , eval_str = True )
721726 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__ )
724728 )
725729
726730 def test_pep_695_generic_function_with_future_annotations (self ):
@@ -737,17 +741,19 @@ def test_pep_695_generic_function_with_future_annotations(self):
737741 self .assertIs (generic_func_annotations ["z" ].__origin__ , func_t_params [2 ])
738742 self .assertIs (generic_func_annotations ["zz" ].__origin__ , func_t_params [2 ])
739743
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+ ):
741747 self .assertEqual (
742748 set (
743749 annotationlib .get_annotations (
744750 inspect_stringized_annotations_pep695 .generic_function_2 ,
745- eval_str = True
751+ eval_str = True ,
746752 ).values ()
747753 ),
748754 set (
749755 inspect_stringized_annotations_pep695 .generic_function_2 .__type_params__
750- )
756+ ),
751757 )
752758
753759 def test_pep_695_generic_method_with_future_annotations (self ):
@@ -761,23 +767,27 @@ def test_pep_695_generic_method_with_future_annotations(self):
761767 }
762768 self .assertEqual (
763769 generic_method_annotations ,
764- {"x" : params ["Foo" ], "y" : params ["Bar" ], "return" : None }
770+ {"x" : params ["Foo" ], "y" : params ["Bar" ], "return" : None },
765771 )
766772
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+ ):
768776 self .assertEqual (
769777 set (
770778 annotationlib .get_annotations (
771779 inspect_stringized_annotations_pep695 .D .generic_method_2 ,
772- eval_str = True
780+ eval_str = True ,
773781 ).values ()
774782 ),
775783 set (
776784 inspect_stringized_annotations_pep695 .D .generic_method_2 .__type_params__
777- )
785+ ),
778786 )
779787
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+ ):
781791 self .assertEqual (
782792 annotationlib .get_annotations (
783793 inspect_stringized_annotations_pep695 .E , eval_str = True
@@ -789,20 +799,20 @@ def test_pep_695_generics_with_future_annota
802E
tions_nested_in_function(self):
789799 results = inspect_stringized_annotations_pep695 .nested ()
790800
791801 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__ )
794803 )
795804 self .assertEqual (
796805 set (results .F_meth_annotations .values ()),
797- set (results .F .generic_method .__type_params__ )
806+ set (results .F .generic_method .__type_params__ ),
798807 )
799808 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__ )
802810 )
803811 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__
81
8B92
4+ ),
815+ set (),
806816 )
807817
808818 self .assertEqual (results .G_annotations , {"x" : str })
@@ -823,7 +833,9 @@ def evaluate(format, exc=NotImplementedError):
823833 with self .assertRaises (NameError ):
824834 annotationlib .call_evaluate_function (evaluate , annotationlib .Format .VALUE )
825835 self .assertEqual (
826- annotationlib .call_evaluate_function (evaluate , annotationlib .Format .FORWARDREF ),
836+ annotationlib .call_evaluate_function (
837+ evaluate , annotationlib .Format .FORWARDREF
838+ ),
827839 annotationlib .ForwardRef ("undefined" ),
828840 )
829841 self .assertEqual (
@@ -853,12 +865,14 @@ class Y(metaclass=Meta):
853865 self .assertEqual (get_annotate_function (Y )(Format .VALUE ), {"b" : float })
854866
855867 def test_unannotated_meta (self ):
856- class Meta (type ): pass
868+ class Meta (type ):
869+ pass
857870
858871 class X (metaclass = Meta ):
859872 a : str
860873
861- class Y (X ): pass
874+ class Y (X ):
875+ pass
862876
863877 self .assertEqual (get_annotations (Meta ), {})
864878 self .assertIs (get_annotate_function (Meta ), None )
@@ -907,6 +921,13 @@ class D(metaclass=Meta):
907921 self .assertEqual (get_annotations (c ), c .expected_annotations )
908922 annotate_func = get_annotate_function (c )
909923 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+ )
911927 else :
912928 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