Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 31 additions & 8 deletions stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -181,22 +181,45 @@ 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.
Comment thread
AlexWaygood marked this conversation as resolved.
Resolved
__base__: Final[type | None]
@final
@property # `types.MemberDescriptorType` on CPython
def __base__(self) -> type | None: ...
__bases__: tuple[type, ...]
__basicsize__: Final[int]
@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]
__dictoffset__: Final[int]
__flags__: Final[int]
__itemsize__: Final[int]
@final
@property # `types.MemberDescriptorType` on CPython
def __dictoffset__(self) -> int: ...
@final
@property # `types.MemberDescriptorType` on CPython
def __flags__(self) -> int: ...
@final
@property # `types.MemberDescriptorType` on CPython
def __itemsize__(self) -> int: ...
__module__: str
__mro__: Final[tuple[type, ...]]
# 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, ...]: ...
@final
@property # `types.GetSetDescriptorType` on CPython
def __text_signature__(self) -> str | None: ...
@final
@property # `types.MemberDescriptorType` on CPython
def __weakrefoffset__(self) -> int: ...

__name__: str
__qualname__: str
__text_signature__: Final[str | None]
__weakrefoffset__: Final[int]

@overload
def __init__(self, o: object, /) -> None: ...
Expand Down
Loading