mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-10 05:51:52 +08:00
Reduce use of Any in builtins (#6292)
This commit is contained in:
@@ -109,11 +109,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: ...
|
||||
|
||||
@@ -170,7 +170,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: ...
|
||||
@@ -1013,6 +1013,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 | AST,
|
||||
@@ -1037,18 +1038,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]):
|
||||
@@ -1077,14 +1083,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]: ...
|
||||
|
||||
# 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, ...], ...]
|
||||
@@ -1334,6 +1341,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]: ...
|
||||
@@ -1352,6 +1362,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]):
|
||||
@@ -1433,8 +1445,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: ...
|
||||
|
||||
Reference in New Issue
Block a user