Make return type of functools.cache_property covariant (#10053)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This commit is contained in:
Nikita Sobolev
2024-02-18 02:38:46 +03:00
committed by GitHub
parent 3fa6374c9a
commit 863d22a239
2 changed files with 25 additions and 5 deletions

View File

@@ -46,3 +46,22 @@ def check_cached_property_settable(x: int) -> None:
assert_type(b.x, int)
b.x = x
assert_type(b.x, int)
# https://github.com/python/typeshed/issues/10048
class Parent: ...
class Child(Parent): ...
class X:
@cached_property
def some(self) -> Parent:
return Parent()
class Y(X):
@cached_property
def some(self) -> Child: # safe override
return Child()