From c6d0ff187edb3742f05d76230f275105cc959ffb Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Sun, 1 Nov 2026 19:08:24 +0000 Subject: [PATCH 1/3] Restore read-only properties on builtins.type --- stdlib/builtins.pyi | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 0075adf561c2..cf2cf8a22985 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -182,21 +182,29 @@ class classmethod(Generic[_T, _P, _R_co]): @disjoint_base class type: # object.__base__ is None. Otherwise, it would be a type. - __base__: Final[type | None] + @property + def __base__(self) -> type | None: ... __bases__: tuple[type, ...] - __basicsize__: Final[int] + @property + def __basicsize__(self) -> int: ... # type.__dict__ is read-only at runtime, but that can't be expressed currently. # See https://github.com/python/typeshed/issues/11033 for a discussion. __dict__: Final[types.MappingProxyType[str, Any]] # type: ignore[assignment] - __dictoffset__: Final[int] - __flags__: Final[int] - __itemsize__: Final[int] + @property + def __dictoffset__(self) -> int: ... + @property + def __flags__(self) -> int: ... + @property + def __itemsize__(self) -> int: ... __module__: str - __mro__: Final[tuple[type, ...]] + @property + def __mro__(self) -> tuple[type, ...]: ... __name__: str __qualname__: str - __text_signature__: Final[str | None] - __weakrefoffset__: Final[int] + @property + def __text_signature__(self) -> str | None: ... + @property + def __weakrefoffset__(self) -> int: ... @overload def __init__(self, o: object, /) -> None: ... From 11ea43e61f8184c415186c420c0a056dbf072cb6 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Wed, 18 Nov 2026 15:13:58 +0000 Subject: [PATCH 2/3] Mark the read-only properties on builtins.type as final --- stdlib/builtins.pyi | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index cf2cf8a22985..d5ea6bfedaf3 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -181,31 +181,46 @@ class classmethod(Generic[_T, _P, _R_co]): @disjoint_base class type: + # On CPython, `type.__dict__["__basicsize__"]` holds a member descriptor, while `int.__basicsize__` returns an integer. + # Annotating these attributes as `types.MemberDescriptorType` would give reads the type `Any` because its `__get__` + # stub returns `Any`. We use `@property` so type checkers infer each attribute's type from its getter. + # object.__base__ is None. Otherwise, it would be a type. - @property + @final + @property # `types.MemberDescriptorType` on CPython def __base__(self) -> type | None: ... __bases__: tuple[type, ...] - @property + @final + @property # `types.MemberDescriptorType` on CPython def __basicsize__(self) -> int: ... # type.__dict__ is read-only at runtime, but that can't be expressed currently. # See https://github.com/python/typeshed/issues/11033 for a discussion. __dict__: Final[types.MappingProxyType[str, Any]] # type: ignore[assignment] - @property + @final + @property # `types.MemberDescriptorType` on CPython def __dictoffset__(self) -> int: ... - @property + @final + @property # `types.MemberDescriptorType` on CPython def __flags__(self) -> int: ... - @property + @final + @property # `types.MemberDescriptorType` on CPython def __itemsize__(self) -> int: ... __module__: str - @property + # As with member descriptors, the stub for `types.GetSetDescriptorType.__get__` returns `Any`. + # Type checkers special-case `property` so they can infer each attribute's type from its getter. + @final + @property # `types.GetSetDescriptorType` on CPython (`types.MemberDescriptorType` before 3.12) def __mro__(self) -> tuple[type, ...]: ... - __name__: str - __qualname__: str - @property + @final + @property # `types.GetSetDescriptorType` on CPython def __text_signature__(self) -> str | None: ... - @property + @final + @property # `types.MemberDescriptorType` on CPython def __weakrefoffset__(self) -> int: ... + __name__: str + __qualname__: str + @overload def __init__(self, o: object, /) -> None: ... @overload From 2347880833557d456968e21e7530463bf594e828 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Wed, 18 Nov 2026 15:23:54 +0000 Subject: [PATCH 3/3] Update stdlib/builtins.pyi --- stdlib/builtins.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index d5ea6bfedaf3..af48e94f5913 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -184,7 +184,7 @@ class type: # On CPython, `type.__dict__["__basicsize__"]` holds a member descriptor, while `int.__basicsize__` returns an integer. # Annotating these attributes as `types.MemberDescriptorType` would give reads the type `Any` because its `__get__` # stub returns `Any`. We use `@property` so type checkers infer each attribute's type from its getter. - + # # object.__base__ is None. Otherwise, it would be a type. @final @property # `types.MemberDescriptorType` on CPython