@@ -371,24 +371,11 @@ def __convert_to_ast(self, other):
371371 elif type (other ) in (list , tuple , set ):
372372 extra_names = {}
373373 elts = []
374-
375- # For sets of types, sort elements by name for consistent ordering.
376- if type (other ) is set and all (isinstance (x , type ) for x in other ):
377- # Sort the elements by name to ensure deterministic output.
378- sorted_elts = sorted (other , key = lambda x : x .__name__ )
379- for elt in sorted_elts :
380- new_elt , new_extra_names = self .__convert_to_ast (elt )
381- if new_extra_names is not None :
382- extra_names .update (new_extra_names )
383- elts .append (new_elt )
384- else :
385- # For lists, tuples, and other sets, preserve the original order.
386- for elt in other :
387- new_elt , new_extra_names = self .__convert_to_ast (elt )
388- if new_extra_names is not None :
389- extra_names .update (new_extra_names )
390- elts .append (new_elt )
391-
374+ for elt in other :
375+ new_elt , new_extra_names = self .__convert_to_ast (elt )
376+ if new_extra_names is not None :
377+ extra_names .update (new_extra_names )
378+ elts .append (new_elt )
392379 ast_class = {list : ast .List , tuple : ast .Tuple , set : ast .Set }[type (other )]
393380 return ast_class (elts ), extra_names
394381 else :
@@ -830,10 +817,6 @@ def _stringify_single(anno):
830817 return anno
831818 elif isinstance (anno , _Template ):
832819 return ast .unparse (_template_to_ast (anno ))
833- elif isinstance (anno , set ) and all (isinstance (x , type ) for x in anno ):
834- # Sort set elements by name to ensure consistent ordering.
835- sorted_elements = sorted (anno , key = lambda x : x .__name__ )
836- return "{" + ", " .join (x .__name__ for x in sorted_elements ) + "}"
837820 else :
838821 return repr (anno )
839822
@@ -1039,17 +1022,10 @@ def annotations_to_string(annotations):
10391022
10401023 Always returns a fresh a dictionary.
10411024 """
1042- result = {}
1043- for n , t in annotations .items ():
1044- if isinstance (t , str ):
1045- result [n ] = t
1046- elif isinstance (t , set ) and all (isinstance (x , type ) for x in t ):
1047- # Sort set elements by name to ensure consistent ordering.
1048- sorted_elements = sorted (t , key = lambda x : x .__name__ )
1049- result [n ] = "{" + ", " .join (x .__name__ for x in sorted_elements ) + "}"
1050- else :
1051- result [n ] = type_repr (t )
1052- return result
1025+ return {
1026+ n : t if isinstance (t , str ) else type_repr (t )
1027+ for n , t in annotations .items ()
1028+ }
10531029
10541030
10551031def _get_and_call_annotate (obj , format ):
0 commit comments