From f5c1a6f6b1e67d82c621b2e53c09642f3ac88869 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Wed, 2 Mar 2022 10:24:21 +0000 Subject: [PATCH 1/4] Make several fields read-only for `type`, `staticmethod` and `classmethod` --- stdlib/builtins.pyi | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 87623557d7bc..bb8f69716a2e 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -115,8 +115,10 @@ class object: def __init_subclass__(cls) -> None: ... class staticmethod(Generic[_R_co]): - __func__: Callable[..., _R_co] - __isabstractmethod__: bool + @property + def __func__(self) -> Callable[..., _R_co]: ... + @property + def __isabstractmethod__(self) -> bool: ... def __init__(self: staticmethod[_R_co], __f: Callable[..., _R_co]) -> None: ... def __get__(self, __obj: _T, __type: type[_T] | None = ...) -> Callable[..., _R_co]: ... if sys.version_info >= (3, 10): @@ -126,8 +128,10 @@ class staticmethod(Generic[_R_co]): def __call__(self, *args: Any, **kwargs: Any) -> _R_co: ... class classmethod(Generic[_R_co]): - __func__: Callable[..., _R_co] - __isabstractmethod__: bool + @property + def __func__(self) -> Callable[..., _R_co]: ... + @property + def __isabstractmethod__(self) -> bool: ... def __init__(self: classmethod[_R_co], __f: Callable[..., _R_co]) -> None: ... def __get__(self, __obj: _T, __type: type[_T] | None = ...) -> Callable[..., _R_co]: ... if sys.version_info >= (3, 10): @@ -136,19 +140,28 @@ class classmethod(Generic[_R_co]): __wrapped__: Callable[..., _R_co] class type: - __base__: type + @property + def __base__(self) -> type: ... __bases__: tuple[type, ...] - __basicsize__: int - __dict__: dict[str, Any] - __dictoffset__: int - __flags__: int - __itemsize__: int + @property + def __basicsize__(self) -> int: ... + @property + def __dict__(self) -> dict[str, Any]: ... + @property + def __dictoffset__(self) -> int: ... + @property + def __flags__(self) -> int: ... + @property + def __itemsize__(self) -> int: ... __module__: str - __mro__: tuple[type, ...] + @property + def __mro__(self) -> tuple[type, ...]: ... __name__: str __qualname__: str - __text_signature__: str | None - __weakrefoffset__: int + @property + def __text_signature__(self) -> str | None: ... + @property + def __weakrefoffset__(self) -> int: ... @overload def __init__(self, __o: object) -> None: ... @overload From 82f55c5d7df78c5a1d1899760538663c14ba8e9c Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Wed, 2 Mar 2022 10:30:34 +0000 Subject: [PATCH 2/4] Update builtins.pyi --- stdlib/builtins.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index bb8f69716a2e..51d1e2386447 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -146,7 +146,7 @@ class type: @property def __basicsize__(self) -> int: ... @property - def __dict__(self) -> dict[str, Any]: ... + def __dict__(self) -> dict[str, Any]: ... # type: ignore[override] @property def __dictoffset__(self) -> int: ... @property From c8d11e6b0bfdc157a977541e90a246be2ca4c5c5 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Wed, 2 Mar 2022 10:34:21 +0000 Subject: [PATCH 3/4] Update py3_common.txt --- tests/stubtest_allowlists/py3_common.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/stubtest_allowlists/py3_common.txt b/tests/stubtest_allowlists/py3_common.txt index e4fe05c80536..93ff491ff169 100644 --- a/tests/stubtest_allowlists/py3_common.txt +++ b/tests/stubtest_allowlists/py3_common.txt @@ -48,6 +48,7 @@ sqlite3.Binary.__contains__ # C type that implements __getitem__ builtins.object.__init__ # default C signature is incorrect builtins.property.__get__ # this function can accept no value for the type parameter. builtins.staticmethod.__get__ # this function can accept no value for the type parameter. +builtins.type.__dict__ # read-only but not actually a property; stubtest thinks it's a mutable attribute. bz2.BZ2Decompressor.__init__ # function does not accept parameters but C signature is set # The following CodecInfo properties are added in __new__ codecs.CodecInfo.decode From 24bf0c8fe63b9104e6f0b5ce208bb7784f6185a1 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Wed, 2 Mar 2022 14:21:37 +0000 Subject: [PATCH 4/4] Update stdlib/builtins.pyi Co-authored-by: Bas van Beek <43369155+BvB93@users.noreply.github.com> --- stdlib/builtins.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 51d1e2386447..50ced396888f 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -146,7 +146,7 @@ class type: @property def __basicsize__(self) -> int: ... @property - def __dict__(self) -> dict[str, Any]: ... # type: ignore[override] + def __dict__(self) -> types.MappingProxyType[str, Any]: ... # type: ignore[override] @property def __dictoffset__(self) -> int: ... @property