@@ -509,7 +509,7 @@ def add_fns_to_class(self, cls):
509509 for name , fn in zip (self .names , fns ):
510510 fn .__qualname__ = f"{ cls .__qualname__ } .{ fn .__name__ } "
511511 if annotations := self .method_annotations .get (name ):
512- fn .__annotate__ = self . make_annotate_function (annotations )
512+ fn .__annotate__ = _make_annotate_function (annotations )
513513
514514 if self .unconditional_adds .get (name , False ):
515515 setattr (cls , name , fn )
@@ -525,33 +525,33 @@ def add_fns_to_class(self, cls):
525525
526526 raise TypeError (error_msg )
527527
528- @staticmethod
529- def make_annotate_function (annotations ):
530- # Create an __annotate__ function for a dataclass
531- # Try to return annotations in the same format as they would be
532- # from a regular __init__ function
533- def __annotate__ (format ):
534- match format :
535- case annotationlib .Format .VALUE | annotationlib .Format .FORWARDREF :
536- return {
537- k : v .evaluate (format = format )
538- if isinstance (v , annotationlib .ForwardRef ) else v
539- for k , v in annotations .items ()
540- }
541- case annotationlib .Format .STRING :
542- string_annos = {}
543- for k , v in annotations .items ():
544- if isinstance (v , str ):
545- string_annos [k ] = v
546- elif isinstance (v , annotationlib .ForwardRef ):
547- string_annos [k ] = v .evaluate (format = annotationlib .Format .STRING )
548- else :
549- string_annos [k ] = annotationlib .type_repr (v )
550- return string_annos
551- case _:
552- raise NotImplementedError (format )
553528
554- return __annotate__
529+ def _make_annotate_function (annotations ):
530+ # Create an __annotate__ function for a dataclass
531+ # Try to return annotations in the same format as they would be
532+ # from a regular __init__ function
533+ def __annotate__ (format ):
534+ match format :
535+ case annotationlib .Format .VALUE | annotationlib .Format .FORWARDREF :
536+ return {
537+ k : v .evaluate (format = format )
538+ if isinstance (v , annotationlib .ForwardRef ) else v
539+ for k , v in annotations .items ()
540+ }
541+ case annotationlib .Format .STRING :
542+ string_annos = {}
543+ for k , v in annotations .items ():
544+ if isinstance (v , str ):
545+ string_annos [k ] = v
546+ elif isinstance (v , annotationlib .ForwardRef ):
547+ string_annos [k ] = v .evaluate (format = annotationlib .Format .STRING )
548+ else :
549+ string_annos [k ] = annotationlib .type_repr (v )
550+ return string_annos
551+ case _:
552+ raise NotImplementedError (format )
553+
554+ return __annotate__
555555
556556
557557def _field_assign (frozen , name , value , self_name ):
0 commit comments