From b28b5f084bbe5f78cb7486d3e0722cd3e7ac22ca Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Tue, 5 Nov 2019 12:46:33 +0100 Subject: [PATCH 1/2] Add functools.cached_property Part of #3319 --- stdlib/3/functools.pyi | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/stdlib/3/functools.pyi b/stdlib/3/functools.pyi index 78a3466eaa45..2f3176f6d3c4 100644 --- a/stdlib/3/functools.pyi +++ b/stdlib/3/functools.pyi @@ -76,3 +76,14 @@ class _SingleDispatchCallable(Generic[_T]): def __call__(self, *args: Any, **kwargs: Any) -> _T: ... def singledispatch(func: Callable[..., _T]) -> _SingleDispatchCallable[_T]: ... + +if sys.version_info >= (3, 8): + class cached_property(Generic[_S, _T]): + func: Callable[[_S], _T] + attrname: Optional[str] + def __init__(self, func: Callable[[_S], _T]) -> None: ... + @overload + def __get__(self, instance: None, owner: Optional[Any] = ...) -> cached_property[_S, _T]: ... + @overload + def __get__(self, instance: _S, owner: Optional[Any] = ...) -> _T: ... + def __set_name__(self, owner: Any, name: str) -> None: ... From 47a804e79c38b6eab04f557e2185d484d84a933a Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Wed, 6 Nov 2019 10:05:19 +0100 Subject: [PATCH 2/2] Make owner types more strict --- stdlib/3/functools.pyi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stdlib/3/functools.pyi b/stdlib/3/functools.pyi index 2f3176f6d3c4..a23ef6f5f8e0 100644 --- a/stdlib/3/functools.pyi +++ b/stdlib/3/functools.pyi @@ -83,7 +83,7 @@ if sys.version_info >= (3, 8): attrname: Optional[str] def __init__(self, func: Callable[[_S], _T]) -> None: ... @overload - def __get__(self, instance: None, owner: Optional[Any] = ...) -> cached_property[_S, _T]: ... + def __get__(self, instance: None, owner: Optional[Type[_S]] = ...) -> cached_property[_S, _T]: ... @overload - def __get__(self, instance: _S, owner: Optional[Any] = ...) -> _T: ... - def __set_name__(self, owner: Any, name: str) -> None: ... + def __get__(self, instance: _S, owner: Optional[Type[_S]] = ...) -> _T: ... + def __set_name__(self, owner: Type[_S], name: str) -> None: ...