Skip to content

Commit e6bc7a0

Browse files
committed
Don't create an unused new cache wrapper for cached annotate functions
1 parent a83ca8f commit e6bc7a0

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

Lib/annotationlib.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -931,15 +931,10 @@ def _direct_call_annotate(func, annotate, format):
931931
if isinstance(annotate, functools.partial):
932932
return functools.partial(func, *annotate.args, **annotate.keywords)(format)
933933

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-
934+
# If annotate is a cached function, we've now updated the function data, so
935+
# let's not use the old cache. Furthermore, we're about to call the function
936+
# and never use it again, so let's not bother trying to cache it.
937+
# Or, if it's a normal function or unsupported callable, we should just call it.
943938
return func(format)
944939

945940

0 commit comments

Comments
 (0)