diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 32da1b20d..d898a3629 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -106,7 +106,10 @@ class object: def __delattr__(self, name: str) -> None: ... def __sizeof__(self) -> int: ... def __reduce__(self) -> Union[str, Tuple[Any, ...]]: ... - def __reduce_ex__(self, protocol: int) -> Union[str, Tuple[Any, ...]]: ... + if sys.version_info >= (3, 8): + def __reduce_ex__(self, protocol: SupportsIndex) -> str | Tuple[Any, ...]: ... + else: + def __reduce_ex__(self, protocol: int) -> str | Tuple[Any, ...]: ... def __dir__(self) -> Iterable[str]: ... def __init_subclass__(cls) -> None: ... @@ -171,7 +174,7 @@ class int: @overload def __new__(cls: Type[_T], x: Union[str, bytes, SupportsInt, SupportsIndex, _SupportsTrunc] = ...) -> _T: ... @overload - def __new__(cls: Type[_T], x: Union[str, bytes, bytearray], base: int) -> _T: ... + def __new__(cls: Type[_T], x: Union[str, bytes, bytearray], base: SupportsIndex) -> _T: ... if sys.version_info >= (3, 8): def as_integer_ratio(self) -> Tuple[int, Literal[1]]: ... @property @@ -186,10 +189,10 @@ class int: def bit_length(self) -> int: ... if sys.version_info >= (3, 10): def bit_count(self) -> int: ... - def to_bytes(self, length: int, byteorder: Literal["little", "big"], *, signed: bool = ...) -> bytes: ... + def to_bytes(self, length: SupportsIndex, byteorder: Literal["little", "big"], *, signed: bool = ...) -> bytes: ... @classmethod def from_bytes( - cls, bytes: Union[Iterable[int], SupportsBytes], byteorder: Literal["little", "big"], *, signed: bool = ... + cls, bytes: Iterable[SupportsIndex] | SupportsBytes, byteorder: Literal["little", "big"], *, signed: bool = ... ) -> int: ... # TODO buffer object argument def __add__(self, x: int) -> int: ... def __sub__(self, x: int) -> int: ... @@ -226,7 +229,7 @@ class int: def __trunc__(self) -> int: ... def __ceil__(self) -> int: ... def __floor__(self) -> int: ... - def __round__(self, ndigits: Optional[int] = ...) -> int: ... + def __round__(self, ndigits: SupportsIndex = ...) -> int: ... def __getnewargs__(self) -> Tuple[int]: ... def __eq__(self, x: object) -> bool: ... def __ne__(self, x: object) -> bool: ... @@ -280,7 +283,7 @@ class float: @overload def __round__(self, ndigits: None = ...) -> int: ... @overload - def __round__(self, ndigits: int) -> float: ... + def __round__(self, ndigits: SupportsIndex) -> float: ... def __eq__(self, x: object) -> bool: ... def __ne__(self, x: object) -> bool: ... def __lt__(self, x: float) -> bool: ... @@ -716,7 +719,7 @@ class slice(object): @overload def __init__(self, start: Any, stop: Any, step: Any = ...) -> None: ... __hash__: None # type: ignore - def indices(self, len: int) -> Tuple[int, int, int]: ... + def indices(self, len: SupportsIndex) -> Tuple[int, int, int]: ... class tuple(Sequence[_T_co], Generic[_T_co]): def __new__(cls: Type[_T], iterable: Iterable[_T_co] = ...) -> _T: ... @@ -735,10 +738,10 @@ class tuple(Sequence[_T_co], Generic[_T_co]): def __add__(self, x: Tuple[_T_co, ...]) -> Tuple[_T_co, ...]: ... @overload def __add__(self, x: Tuple[_T, ...]) -> Tuple[Union[_T_co, _T], ...]: ... - def __mul__(self, n: int) -> Tuple[_T_co, ...]: ... - def __rmul__(self, n: int) -> Tuple[_T_co, ...]: ... + def __mul__(self, n: SupportsIndex) -> Tuple[_T_co, ...]: ... + def __rmul__(self, n: SupportsIndex) -> Tuple[_T_co, ...]: ... def count(self, __value: Any) -> int: ... - def index(self, __value: Any, __start: int = ..., __stop: int = ...) -> int: ... + def index(self, __value: Any, __start: SupportsIndex = ..., __stop: SupportsIndex = ...) -> int: ... if sys.version_info >= (3, 9): def __class_getitem__(cls, item: Any) -> GenericAlias: ... @@ -759,10 +762,10 @@ class list(MutableSequence[_T], Generic[_T]): def copy(self) -> List[_T]: ... def append(self, __object: _T) -> None: ... def extend(self, __iterable: Iterable[_T]) -> None: ... - def pop(self, __index: int = ...) -> _T: ... - def index(self, __value: _T, __start: int = ..., __stop: int = ...) -> int: ... + def pop(self, __index: SupportsIndex = ...) -> _T: ... + def index(self, __value: _T, __start: SupportsIndex = ..., __stop: SupportsIndex = ...) -> int: ... def count(self, __value: _T) -> int: ... - def insert(self, __index: int, __object: _T) -> None: ... + def insert(self, __index: SupportsIndex, __object: _T) -> None: ... def remove(self, __value: _T) -> None: ... def reverse(self) -> None: ... @overload @@ -784,9 +787,9 @@ class list(MutableSequence[_T], Generic[_T]): def __delitem__(self, i: Union[SupportsIndex, slice]) -> None: ... def __add__(self, x: List[_T]) -> List[_T]: ... def __iadd__(self: _S, x: Iterable[_T]) -> _S: ... - def __mul__(self, n: int) -> List[_T]: ... - def __rmul__(self, n: int) -> List[_T]: ... - def __imul__(self: _S, n: int) -> _S: ... + def __mul__(self, n: SupportsIndex) -> List[_T]: ... + def __rmul__(self, n: SupportsIndex) -> List[_T]: ... + def __imul__(self: _S, n: SupportsIndex) -> _S: ... def __contains__(self, o: object) -> bool: ... def __reversed__(self) -> Iterator[_T]: ... def __gt__(self, x: List[_T]) -> bool: ... @@ -1296,7 +1299,7 @@ def round(number: SupportsRound[Any]) -> int: ... @overload def round(number: SupportsRound[Any], ndigits: None) -> int: ... @overload -def round(number: SupportsRound[_T], ndigits: int) -> _T: ... +def round(number: SupportsRound[_T], ndigits: SupportsIndex) -> _T: ... def setattr(__obj: Any, __name: str, __value: Any) -> None: ... @overload def sorted(__iterable: Iterable[SupportsLessThanT], *, key: None = ..., reverse: bool = ...) -> List[SupportsLessThanT]: ... diff --git a/stubs/polib/polib.pyi b/stubs/polib/polib.pyi index b73f8eaa2..ea4442877 100644 --- a/stubs/polib/polib.pyi +++ b/stubs/polib/polib.pyi @@ -1,5 +1,6 @@ import textwrap from typing import IO, Any, Callable, Dict, Generic, List, Optional, Text, Tuple, Type, TypeVar, Union, overload +from typing_extensions import SupportsIndex _TB = TypeVar("_TB", bound="_BaseEntry") _TP = TypeVar("_TP", bound="POFile") @@ -35,7 +36,7 @@ class _BaseFile(List[_TB]): def __contains__(self, entry: _TB) -> bool: ... # type: ignore # AttributeError otherwise def __eq__(self, other: object) -> bool: ... def append(self, entry: _TB) -> None: ... - def insert(self, index: int, entry: _TB) -> None: ... + def insert(self, index: SupportsIndex, entry: _TB) -> None: ... def metadata_as_entry(self) -> POEntry: ... def save(self, fpath: Optional[Text] = ..., repr_method: str = ...) -> None: ... def find(self, st: Text, by: str = ..., include_obsolete_entries: bool = ..., msgctxt: bool = ...) -> Optional[_TB]: ...