Skip to content

Commit

Permalink
Add a typeshed alias to the type accepted by int constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
hamdanal committed Sep 12, 2023
1 parent f0a7993 commit cdf34f8
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 14 deletions.
7 changes: 5 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, 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,6 @@ 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]]]

# Any thing that can be passed to the int constructor
_AcceptedByInt: TypeAlias = str | ReadableBuffer | SupportsInt | SupportsIndex | SupportsTrunc # noqa: Y047
5 changes: 2 additions & 3 deletions stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ from _typeshed import (
SupportsRDivMod,
SupportsRichComparison,
SupportsRichComparisonT,
SupportsTrunc,
SupportsWrite,
_AcceptedByInt,
)
from collections.abc import Awaitable, Callable, Iterable, Iterator, MutableSet, Reversible, Set as AbstractSet, Sized
from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper
Expand All @@ -48,7 +48,6 @@ from typing import ( # noqa: Y022
SupportsBytes,
SupportsComplex,
SupportsFloat,
SupportsInt,
TypeVar,
overload,
type_check_only,
Expand Down Expand Up @@ -221,7 +220,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: _AcceptedByInt = ...) -> Self: ...
@overload
def __new__(cls, __x: str | bytes | bytearray, base: SupportsIndex) -> Self: ...
if sys.version_info >= (3, 8):
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 Incomplete, Unused, _AcceptedByInt
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[_AcceptedByInt], passfds: Sequence[int]) -> int: ...
1 change: 1 addition & 0 deletions stubs/openpyxl/openpyxl/descriptors/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ _M = TypeVar("_M", int, float)

_ExpectedTypeParam: TypeAlias = type[_T] | tuple[type[_T], ...]
_ConvertibleToMultiCellRange: TypeAlias = MultiCellRange | str | Iterable[CellRange]
# TODO: replace by `_typeshed._AcceptedByInt` when it is included in type checkers
_ConvertibleToInt: TypeAlias = int | str | ReadableBuffer | SupportsInt | SupportsIndex | SupportsTrunc
_ConvertibleToFloat: TypeAlias = float | SupportsFloat | SupportsIndex | str | ReadableBuffer
# Since everything is convertible to a bool, this restricts to only intended expected types
Expand Down
1 change: 1 addition & 0 deletions stubs/pyasn1/pyasn1/type/univ.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ from typing_extensions import Self, SupportsIndex, TypeAlias
from pyasn1.type import base, constraint, namedtype, namedval
from pyasn1.type.tag import TagSet

# TODO: replace by `_typeshed._AcceptedByInt` when it is included in type checkers
_SizedIntegerable: TypeAlias = ReadableBuffer | str | SupportsInt | SupportsIndex | SupportsTrunc

NoValue = base.NoValue
Expand Down
1 change: 1 addition & 0 deletions stubs/python-xlib/Xlib/protocol/rq.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ from Xlib.ext.xinput import ClassInfoClass
from Xlib.protocol import display

_T = TypeVar("_T")
# TODO: replace by `_typeshed._AcceptedByInt` when it is included in type checkers
_IntNew: TypeAlias = str | ReadableBuffer | SupportsInt | SupportsIndex | SupportsTrunc
_ModifierMappingList8Elements: TypeAlias = Sequence[Sequence[int]]

Expand Down

0 comments on commit cdf34f8

Please sign in to comment.