From b67c936b279219dd9a80e6e338d9335bd1a9f714 Mon Sep 17 00:00:00 2001 From: Eric Wieser Date: Tue, 12 May 2020 09:59:38 +0100 Subject: [PATCH] Copy cached_property return type annotations to __annotations__ --- Lib/functools.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Lib/functools.py b/Lib/functools.py index 87c7d874389..9c8bef2a2de 100644 --- a/Lib/functools.py +++ b/Lib/functools.py @@ -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