Skip to content

Add a typeshed alias to the type accepted by int constructor #10707

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions stdlib/_typeshed/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ from collections.abc import Awaitable, Callable, Iterable, Sequence, Set as Abst
from dataclasses import Field
from os import PathLike
from types import FrameType, TracebackType
from typing import Any, AnyStr, ClassVar, Generic, Protocol, TypeVar, overload
from typing_extensions import Buffer, Final, Literal, LiteralString, TypeAlias, final
from typing import Any, AnyStr, ClassVar, Generic, Protocol, SupportsFloat, SupportsInt, TypeVar, overload
from typing_extensions import Buffer, Final, Literal, LiteralString, SupportsIndex, TypeAlias, final

_KT = TypeVar("_KT")
_KT_co = TypeVar("_KT_co", covariant=True)
Expand Down Expand Up @@ -312,3 +312,7 @@ TraceFunction: TypeAlias = Callable[[FrameType, str, Any], TraceFunction | None]
# https://github.com/microsoft/pyright/issues/4339
class DataclassInstance(Protocol):
__dataclass_fields__: ClassVar[dict[str, Field[Any]]]

# Anything that can be passed to the int/float constructors
ConvertibleToInt: TypeAlias = str | ReadableBuffer | SupportsInt | SupportsIndex | SupportsTrunc
ConvertibleToFloat: TypeAlias = str | ReadableBuffer | SupportsFloat | SupportsIndex
8 changes: 4 additions & 4 deletions stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import types
from _collections_abc import dict_items, dict_keys, dict_values
from _typeshed import (
AnyStr_co,
ConvertibleToFloat,
ConvertibleToInt,
FileDescriptorOrPath,
OpenBinaryMode,
OpenBinaryModeReading,
Expand All @@ -24,7 +26,6 @@ from _typeshed import (
SupportsRDivMod,
SupportsRichComparison,
SupportsRichComparisonT,
SupportsTrunc,
SupportsWrite,
)
from collections.abc import Awaitable, Callable, Iterable, Iterator, MutableSet, Reversible, Set as AbstractSet, Sized
Expand All @@ -48,7 +49,6 @@ from typing import ( # noqa: Y022
SupportsBytes,
SupportsComplex,
SupportsFloat,
SupportsInt,
TypeVar,
overload,
type_check_only,
Expand Down Expand Up @@ -221,7 +221,7 @@ _LiteralInteger = _PositiveInteger | _NegativeInteger | Literal[0] # noqa: Y026

class int:
@overload
def __new__(cls, __x: str | ReadableBuffer | SupportsInt | SupportsIndex | SupportsTrunc = ...) -> Self: ...
def __new__(cls, __x: ConvertibleToInt = ...) -> Self: ...
@overload
def __new__(cls, __x: str | bytes | bytearray, base: SupportsIndex) -> Self: ...
if sys.version_info >= (3, 8):
Expand Down Expand Up @@ -327,7 +327,7 @@ class int:
def __index__(self) -> int: ...

class float:
def __new__(cls, __x: SupportsFloat | SupportsIndex | str | ReadableBuffer = ...) -> Self: ...
def __new__(cls, __x: ConvertibleToFloat = ...) -> Self: ...
def as_integer_ratio(self) -> tuple[int, int]: ...
def hex(self) -> str: ...
def is_integer(self) -> bool: ...
Expand Down
12 changes: 3 additions & 9 deletions stdlib/multiprocessing/util.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import threading
from _typeshed import Incomplete, ReadableBuffer, SupportsTrunc, Unused
from _typeshed import ConvertibleToInt, Incomplete, Unused
from collections.abc import Callable, Iterable, Mapping, MutableMapping, Sequence
from logging import Logger, _Level as _LoggingLevel
from typing import Any, SupportsInt
from typing_extensions import SupportsIndex
from typing import Any

__all__ = [
"sub_debug",
Expand Down Expand Up @@ -77,9 +76,4 @@ class ForkAwareLocal(threading.local): ...
MAXFD: int

def close_all_fds_except(fds: Iterable[int]) -> None: ...
def spawnv_passfds(
path: bytes,
# args is anything that can be passed to the int constructor
args: Sequence[str | ReadableBuffer | SupportsInt | SupportsIndex | SupportsTrunc],
passfds: Sequence[int],
) -> int: ...
def spawnv_passfds(path: bytes, args: Sequence[ConvertibleToInt], passfds: Sequence[int]) -> int: ...