Add __set__ to functools.cached_property (#9762)

This commit is contained in:
Thomas M Kehrenberg
2023-02-20 13:36:45 +01:00
committed by GitHub
parent 7b975dc144
commit 40d853cbe2
6 changed files with 34 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
from __future__ import annotations
import sys
if sys.version_info >= (3, 8):
from functools import cached_property
from typing_extensions import assert_type
class A:
def __init__(self, x: int):
self.x = x
@cached_property
def x(self) -> int:
return 0
assert_type(A(x=1).x, int)
class B:
@cached_property
def x(self) -> int:
return 0
def check_cached_property_settable(x: int) -> None:
b = B()
assert_type(b.x, int)
b.x = x
assert_type(b.x, int)