@@ -894,9 +894,14 @@ def _get_annotate_attr(annotate, attr, default):
894894 if isinstance (annotate .__call__ , types .MethodType ):
895895 if call_func := getattr (annotate .__call__ , "__func__" , None ):
896896 return getattr (call_func , attr , default )
897- elif isinstance (annotate , type ):
897+
898+ if isinstance (annotate , type ):
898899 return getattr (annotate .__init__ , attr , default )
899- elif (
900+
901+ if (wrapped := getattr (annotate , "__wrapped__" , None )) is not None :
902+ return getattr (wrapped , attr , default )
903+
904+ if (
900905 (functools := sys .modules .get ("functools" , None ))
901906 and isinstance (annotate , functools .partial )
902907 ):
@@ -919,13 +924,22 @@ def _direct_call_annotate(func, annotate, format):
919924 func (inst , format )
920925 return inst
921926
922- # If annotate is a partial function, re-create it with the new function object.
923- # We could call the function directly, but then we'd have to handle placeholders,
924- # and this way should be more robust for future changes.
925927 if functools := sys .modules .get ("functools" , None ):
928+ # If annotate is a partial function, re-create it with the new function object.
929+ # We could call the function directly, but then we'd have to handle placeholders,
930+ # and this way should be more robust for future changes.
926931 if isinstance (annotate , functools .partial ):
927932 return functools .partial (func , * annotate .args , ** annotate .keywords )(format )
928933
934+ # If annotate is a cached function, re-create it with the new function object.
935+ # We want a new, clean, cache, as we've updated the function data, so let's
936+ # re-create with the new function and old cache parameters.
937+ if isinstance (annotate , functools ._lru_cache_wrapper ):
938+ return functools ._lru_cache_wrapper (
939+ func , ** annotate .cache_parameters (),
940+ cache_info_type = (0 , 0 , 0 , annotate .cache_parameters ()["maxsize" ])
941+ )(format )
942+
929943 return func (format )
930944
931945
0 commit comments