mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-07 20:54:28 +08:00
Add __set__ to functools.cached_property (#9762)
This commit is contained in:
committed by
GitHub
parent
7b975dc144
commit
40d853cbe2
@@ -148,6 +148,8 @@ if sys.version_info >= (3, 8):
|
||||
@overload
|
||||
def __get__(self, instance: object, owner: type[Any] | None = None) -> _T: ...
|
||||
def __set_name__(self, owner: type[Any], name: str) -> None: ...
|
||||
# __set__ is not defined at runtime, but @cached_property is designed to be settable
|
||||
def __set__(self, instance: object, value: _T) -> None: ...
|
||||
if sys.version_info >= (3, 9):
|
||||
def __class_getitem__(cls, item: Any) -> GenericAlias: ...
|
||||
|
||||
|
||||
28
test_cases/stdlib/check_functools.py
Normal file
28
test_cases/stdlib/check_functools.py
Normal 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)
|
||||
@@ -16,6 +16,7 @@ builtins.property.__set_name__ # Doesn't actually exist
|
||||
contextlib.AbstractAsyncContextManager.__class_getitem__
|
||||
contextlib.AbstractContextManager.__class_getitem__
|
||||
fractions.Fraction.__new__ # overload is too complicated for stubtest to resolve
|
||||
functools.cached_property.__set__ # Stub is a while lie; see comments in the stub
|
||||
gettext.install
|
||||
gettext.translation
|
||||
hmac.new # Stub is a white lie; see comments in the stub
|
||||
|
||||
@@ -20,6 +20,7 @@ enum.auto.__init__
|
||||
enum.auto.value
|
||||
fractions.Fraction.__new__ # overload is too complicated for stubtest to resolve
|
||||
ftplib.FTP.trust_server_pasv_ipv4_address
|
||||
functools.cached_property.__set__ # Stub is a while lie; see comments in the stub
|
||||
ipaddress.IPv4Interface.hostmask
|
||||
ipaddress.IPv6Interface.hostmask
|
||||
ipaddress._BaseNetwork.broadcast_address
|
||||
|
||||
@@ -46,6 +46,7 @@ dummy_threading.Thread.native_id
|
||||
dummy_threading.local.__new__
|
||||
fractions.Fraction.__new__ # overload is too complicated for stubtest to resolve
|
||||
ftplib.FTP.trust_server_pasv_ipv4_address # Dangerous to use, intentionally undocumented, intentionally missing from typeshed. #6154
|
||||
functools.cached_property.__set__ # Stub is a while lie; see comments in the stub
|
||||
gettext.install # codeset default value is ['unspecified'] so can't be specified
|
||||
gettext.translation # codeset default value is ['unspecified'] so can't be specified
|
||||
hmac.new # Stub is a white lie; see comments in the stub
|
||||
|
||||
@@ -40,6 +40,7 @@ distutils.core.extension_keywords
|
||||
distutils.core.gen_usage
|
||||
distutils.core.setup_keywords
|
||||
fractions.Fraction.__new__ # overload is too complicated for stubtest to resolve
|
||||
functools.cached_property.__set__ # Stub is a while lie; see comments in the stub
|
||||
gettext.install
|
||||
gettext.translation
|
||||
hmac.new # Stub is a white lie; see comments in the stub
|
||||
|
||||
Reference in New Issue
Block a user