Skip to content

Commit 99220cf

Browse files
committed
Alternative approach
1 parent a9a9233 commit 99220cf

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

Lib/functools.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,14 @@ def update_wrapper(wrapper,
6969
for attr in delegated:
7070
if attr == "__annotate__":
7171
def __annotate__(format):
72-
func = _get_get_annotations()
73-
return func(wrapped, format=format)
72+
if format == 1: # VALUE
73+
return getattr(wrapped, "__annotations__", {})
74+
get_annotate_function = _get_get_annotate_function()
75+
call_annotate_function = _get_call_annotate_function()
76+
annotate_function = get_annotate_function(wrapped)
77+
if annotate_function is None:
78+
return {}
79+
return call_annotate_function(annotate_function, format=format)
7480
wrapper.__annotate__ = __annotate__
7581
else:
7682
raise ValueError(f"Unsupported delegated attribute {attr!r}")
@@ -1076,3 +1082,15 @@ def __get__(self, instance, owner=None):
10761082
def _get_get_annotations():
10771083
from annotationlib import get_annotations
10781084
return get_annotations
1085+
1086+
1087+
@cache
1088+
def _get_get_annotate_function():
1089+
from annotationlib import get_annotate_function
1090+
return get_annotate_function
1091+
1092+
1093+
@cache
1094+
def _get_call_annotate_function():
1095+
from annotationlib import call_annotate_function
1096+
return call_annotate_function

0 commit comments

Comments
 (0)