Copy cached_property return type annotations to __annotations__

This commit is contained in:
Eric Wieser 2020-05-12 09:59:38 +01:00 committed by GitHub
parent f3a5b7ada0
commit b67c936b27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 0 deletions

View File

@ -1191,6 +1191,18 @@ class cached_property:
f"({self.attrname!r} and {name!r})."
)
# copy across the annotation for runtime introspection
try:
prop_ann = self.fget.__annotations__['return']
except KeyError:
return
try:
owner_anns = owner.__annotations__
except AttributeError:
owner_anns = owner.__annotations__ = {}
owner_anns[name] = prop_ann
def __get__(self, instance, owner=None):
if instance is None:
return self