@@ -1025,10 +1025,14 @@ def __new__(cls, name, bases, ns, *, total=True, closed=None,
10251025 if "__annotations__" in ns :
10261026 own_annotations = ns ["__annotations__" ]
10271027 elif sys .version_info >= (3 , 14 ):
1028- own_annotate = annotationlib .get_annotate_from_class_namespace (ns )
1028+ if hasattr (annotationlib , "get_annotate_from_class_namespace" ):
1029+ own_annotate = annotationlib .get_annotate_from_class_namespace (ns )
1030+ else :
1031+ # 3.14.0a7 and earlier
1032+ own_annotate = ns .get ("__annotate__" )
10291033 if own_annotate is not None :
10301034 own_annotations = annotationlib .call_annotate_function (
1031- own_annotate , annotationlib . Format .FORWARDREF , owner = tp_dict
1035+ own_annotate , Format .FORWARDREF , owner = tp_dict
10321036 )
10331037 else :
10341038 own_annotations = {}
@@ -1114,14 +1118,14 @@ def __annotate__(format):
11141118 if own_annotate is not None :
11151119 own = annotationlib .call_annotate_function (
11161120 own_annotate , format , owner = tp_dict )
1117- if format != annotationlib . Format .STRING :
1121+ if format != Format .STRING :
11181122 own = {
11191123 n : typing ._type_check (tp , msg , module = tp_dict .__module__ )
11201124 for n , tp in own .items ()
11211125 }
1122- elif format == annotationlib . Format .STRING :
1126+ elif format == Format .STRING :
11231127 own = annotationlib .annotations_to_string (own_annotations )
1124- elif format in (annotationlib . Format .FORWARDREF , annotationlib . Format .VALUE ):
1128+ elif format in (Format .FORWARDREF , Format .VALUE ):
11251129 own = own_checked_annotations
11261130 else :
11271131 raise NotImplementedError (format )
0 commit comments