77import  itertools 
88import  pickle 
99import  unittest 
10- from  annotationlib  import  Format , ForwardRef , get_annotations , get_annotate_function 
10+ from  annotationlib  import  Format , ForwardRef , get_annotations , get_annotate_function ,  annotations_to_source ,  value_to_source 
1111from  typing  import  Unpack 
1212
1313from  test  import  support 
@@ -25,6 +25,11 @@ def wrapper(a, b):
2525    return  wrapper 
2626
2727
28+ class  MyClass :
29+     def  __repr__ (self ):
30+         return  "my repr" 
31+ 
32+ 
2833class  TestFormat (unittest .TestCase ):
2934    def  test_enum (self ):
3035        self .assertEqual (annotationlib .Format .VALUE .value , 1 )
@@ -788,9 +793,8 @@ def __annotations__(self):
788793            annotationlib .get_annotations (ha , format = Format .FORWARDREF ), {"x" : int }
789794        )
790795
791-         # TODO(gh-124412): This should return {'x': 'int'} instead. 
792796        self .assertEqual (
793-             annotationlib .get_annotations (ha , format = Format .SOURCE ), {"x" : int }
797+             annotationlib .get_annotations (ha , format = Format .SOURCE ), {"x" : " int" 
794798        )
795799
796800    def  test_raising_annotations_on_custom_object (self ):
@@ -1078,6 +1082,29 @@ class C:
10781082        self .assertEqual (get_annotate_function (C )(Format .VALUE ), {"a" : int })
10791083
10801084
1085+ class  TestToSource (unittest .TestCase ):
1086+     def  test_value_to_source (self ):
1087+         self .assertEqual (value_to_source (int ), "int" )
1088+         self .assertEqual (value_to_source (MyClass ), "test.test_annotationlib.MyClass" )
1089+         self .assertEqual (value_to_source (len ), "len" )
1090+         self .assertEqual (value_to_source (value_to_source ), "value_to_source" )
1091+         self .assertEqual (value_to_source (times_three ), "times_three" )
1092+         self .assertEqual (value_to_source (...), "..." )
1093+         self .assertEqual (value_to_source (None ), "None" )
1094+         self .assertEqual (value_to_source (1 ), "1" )
1095+         self .assertEqual (value_to_source ("1" ), "'1'" )
1096+         self .assertEqual (value_to_source (Format .VALUE ), repr (Format .VALUE ))
1097+         self .assertEqual (value_to_source (MyClass ()), "my repr" )
1098+ 
1099+     def  test_annotations_to_source (self ):
1100+         self .assertEqual (annotations_to_source ({}), {})
1101+         self .assertEqual (annotations_to_source ({"x" : int }), {"x" : "int" })
1102+         self .assertEqual (annotations_to_source ({"x" : "int" }), {"x" : "int" })
1103+         self .assertEqual (annotations_to_source ({"x" : int , "y" : str }), {"x" : "int" , "y" : "str" })
1104+ 
1105+ 
10811106class  TestAnnotationLib (unittest .TestCase ):
10821107    def  test__all__ (self ):
10831108        support .check__all__ (self , annotationlib )
1109+ 
1110+ 
0 commit comments