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
36 changes: 24 additions & 12 deletions stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ class object:
def __getattribute__(self, __name: str) -> Any: ...
def __delattr__(self, __name: str) -> None: ...
def __sizeof__(self) -> int: ...
def __reduce__(self) -> str | Tuple[Any, ...]: ...
def __reduce__(self) -> str | Tuple[object, ...]: ...
if sys.version_info >= (3, 8):
def __reduce_ex__(self, __protocol: SupportsIndex) -> str | Tuple[Any, ...]: ...
def __reduce_ex__(self, __protocol: SupportsIndex) -> str | Tuple[object, ...]: ...
else:
def __reduce_ex__(self, __protocol: int) -> str | Tuple[Any, ...]: ...
def __reduce_ex__(self, __protocol: int) -> str | Tuple[object, ...]: ...
def __dir__(self) -> Iterable[str]: ...
def __init_subclass__(cls) -> None: ...

Expand Down Expand Up @@ -169,7 +169,7 @@ class type(object):
def __instancecheck__(self, __instance: Any) -> bool: ...
def __subclasscheck__(self, __subclass: type) -> bool: ...
@classmethod
def __prepare__(metacls, __name: str, __bases: Tuple[type, ...], **kwds: Any) -> Mapping[str, Any]: ...
def __prepare__(metacls, __name: str, __bases: Tuple[type, ...], **kwds: Any) -> Mapping[str, object]: ...
if sys.version_info >= (3, 10):
def __or__(self, __t: Any) -> types.UnionType: ...
def __ror__(self, __t: Any) -> types.UnionType: ...
Expand Down Expand Up @@ -1008,6 +1008,7 @@ if sys.version_info >= (3, 10):
@overload
async def anext(__i: SupportsAnext[_T], default: _VT) -> _T | _VT: ...

# TODO: `compile` has a more precise return type in reality; work on a way of expressing that?
if sys.version_info >= (3, 8):
def compile(
source: str | bytes | mod | AST,
Expand All @@ -1032,18 +1033,23 @@ else:

def copyright() -> None: ...
def credits() -> None: ...
def delattr(__obj: Any, __name: str) -> None: ...
def delattr(__obj: object, __name: str) -> None: ...
def dir(__o: object = ...) -> list[str]: ...
@overload
def divmod(__x: SupportsDivMod[_T_contra, _T_co], __y: _T_contra) -> _T_co: ...
@overload
def divmod(__x: _T_contra, __y: SupportsRDivMod[_T_contra, _T_co]) -> _T_co: ...

# The `globals` argument to `eval` has to be `dict[str, Any]` rather than `dict[str, object]` due to invariance.
# (The `globals` argument has to be a "real dict", rather than any old mapping, unlike the `locals` argument.)
def eval(
__source: str | bytes | CodeType, __globals: dict[str, Any] | None = ..., __locals: Mapping[str, Any] | None = ...
__source: str | bytes | CodeType, __globals: dict[str, Any] | None = ..., __locals: Mapping[str, object] | None = ...
) -> Any: ...

# Comment above regarding `eval` applies to `exec` as well
def exec(
__source: str | bytes | CodeType, __globals: dict[str, Any] | None = ..., __locals: Mapping[str, Any] | None = ...
) -> Any: ...
__source: str | bytes | CodeType, __globals: dict[str, Any] | None = ..., __locals: Mapping[str, object] | None = ...
) -> None: ...
def exit(code: object = ...) -> NoReturn: ...

class filter(Iterator[_T], Generic[_T]):
Expand Down Expand Up @@ -1072,14 +1078,15 @@ def hash(__obj: object) -> int: ...
def help(*args: Any, **kwds: Any) -> None: ...
def hex(__number: int | SupportsIndex) -> str: ...
def id(__obj: object) -> int: ...
def input(__prompt: Any = ...) -> str: ...
def input(__prompt: object = ...) -> str: ...
@overload
def iter(__iterable: Iterable[_T]) -> Iterator[_T]: ...
@overload
def iter(__function: Callable[[], _T | None], __sentinel: None) -> Iterator[_T]: ...
@overload
def iter(__function: Callable[[], _T], __sentinel: Any) -> Iterator[_T]: ...
def iter(__function: Callable[[], _T], __sentinel: object) -> Iterator[_T]: ...
Comment thread
AlexWaygood marked this conversation as resolved.

# We need recursive types to express the type of the second argument to `isinstance` properly, hence the use of `Any`
if sys.version_info >= (3, 10):
def isinstance(
__obj: object, __class_or_tuple: type | types.UnionType | Tuple[type | types.UnionType | Tuple[Any, ...], ...]
Expand Down Expand Up @@ -1329,6 +1336,9 @@ def round(number: SupportsRound[Any]) -> int: ...
def round(number: SupportsRound[Any], ndigits: None) -> int: ...
@overload
def round(number: SupportsRound[_T], ndigits: SupportsIndex) -> _T: ...

# See https://github.com/python/typeshed/pull/6292#discussion_r748875189
# for why arg 3 of `setattr` should be annotated with `Any` and not `object`
def setattr(__obj: object, __name: str, __value: Any) -> None: ...
@overload
def sorted(__iterable: Iterable[SupportsLessThanT], *, key: None = ..., reverse: bool = ...) -> list[SupportsLessThanT]: ...
Expand All @@ -1347,6 +1357,8 @@ else:
@overload
def sum(__iterable: Iterable[_T], __start: _S) -> _T | _S: ...

# The argument to `vars()` has to have a `__dict__` attribute, so can't be annotated with `object`
# (A "SupportsDunderDict" protocol doesn't work)
def vars(__object: Any = ...) -> dict[str, Any]: ...

class zip(Iterator[_T_co], Generic[_T_co]):
Expand Down Expand Up @@ -1428,8 +1440,8 @@ class zip(Iterator[_T_co], Generic[_T_co]):

def __import__(
name: str,
globals: Mapping[str, Any] | None = ...,
locals: Mapping[str, Any] | None = ...,
globals: Mapping[str, object] | None = ...,
locals: Mapping[str, object] | None = ...,
fromlist: Sequence[str] = ...,
level: int = ...,
) -> Any: ...
Expand Down