Skip to content

Commit 1a2f718

Browse files
authored
Make several fields read-only for type, staticmethod and classmethod (#7423)
1 parent ea6e06a commit 1a2f718

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

stdlib/builtins.pyi

+26-13
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,10 @@ class object:
115115
def __init_subclass__(cls) -> None: ...
116116

117117
class staticmethod(Generic[_R_co]):
118-
__func__: Callable[..., _R_co]
119-
__isabstractmethod__: bool
118+
@property
119+
def __func__(self) -> Callable[..., _R_co]: ...
120+
@property
121+
def __isabstractmethod__(self) -> bool: ...
120122
def __init__(self: staticmethod[_R_co], __f: Callable[..., _R_co]) -> None: ...
121123
def __get__(self, __obj: _T, __type: type[_T] | None = ...) -> Callable[..., _R_co]: ...
122124
if sys.version_info >= (3, 10):
@@ -126,8 +128,10 @@ class staticmethod(Generic[_R_co]):
126128
def __call__(self, *args: Any, **kwargs: Any) -> _R_co: ...
127129

128130
class classmethod(Generic[_R_co]):
129-
__func__: Callable[..., _R_co]
130-
__isabstractmethod__: bool
131+
@property
132+
def __func__(self) -> Callable[..., _R_co]: ...
133+
@property
134+
def __isabstractmethod__(self) -> bool: ...
131135
def __init__(self: classmethod[_R_co], __f: Callable[..., _R_co]) -> None: ...
132136
def __get__(self, __obj: _T, __type: type[_T] | None = ...) -> Callable[..., _R_co]: ...
133137
if sys.version_info >= (3, 10):
@@ -136,19 +140,28 @@ class classmethod(Generic[_R_co]):
136140
__wrapped__: Callable[..., _R_co]
137141

138142
class type:
139-
__base__: type
143+
@property
144+
def __base__(self) -> type: ...
140145
__bases__: tuple[type, ...]
141-
__basicsize__: int
142-
__dict__: dict[str, Any]
143-
__dictoffset__: int
144-
__flags__: int
145-
__itemsize__: int
146+
@property
147+
def __basicsize__(self) -> int: ...
148+
@property
149+
def __dict__(self) -> types.MappingProxyType[str, Any]: ... # type: ignore[override]
150+
@property
151+
def __dictoffset__(self) -> int: ...
152+
@property
153+
def __flags__(self) -> int: ...
154+
@property
155+
def __itemsize__(self) -> int: ...
146156
__module__: str
147-
__mro__: tuple[type, ...]
157+
@property
158+
def __mro__(self) -> tuple[type, ...]: ...
148159
__name__: str
149160
__qualname__: str
150-
__text_signature__: str | None
151-
__weakrefoffset__: int
161+
@property
162+
def __text_signature__(self) -> str | None: ...
163+
@property
164+
def __weakrefoffset__(self) -> int: ...
152165
@overload
153166
def __init__(self, __o: object) -> None: ...
154167
@overload

tests/stubtest_allowlists/py3_common.txt

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ sqlite3.Binary.__contains__ # C type that implements __getitem__
5454
builtins.object.__init__ # default C signature is incorrect
5555
builtins.property.__get__ # this function can accept no value for the type parameter.
5656
builtins.staticmethod.__get__ # this function can accept no value for the type parameter.
57+
builtins.type.__dict__ # read-only but not actually a property; stubtest thinks it's a mutable attribute.
5758
bz2.BZ2Decompressor.__init__ # function does not accept parameters but C signature is set
5859
# The following CodecInfo properties are added in __new__
5960
codecs.CodecInfo.decode

0 commit comments

Comments
 (0)