stdlib: Add defaults for positional-only parameters (#9655)

This commit is contained in:
Alex Waygood
2023-02-01 21:44:08 +00:00
committed by GitHub
parent 35172c7aab
commit 1d7dda7fa1
30 changed files with 159 additions and 155 deletions

View File

@@ -266,7 +266,7 @@ class int:
def __pow__(self, __x: int, __modulo: None = ...) -> Any: ...
@overload
def __pow__(self, __x: int, __modulo: int) -> int: ...
def __rpow__(self, __x: int, __mod: int | None = ...) -> Any: ...
def __rpow__(self, __x: int, __mod: int | None = None) -> Any: ...
def __and__(self, __n: int) -> int: ...
def __or__(self, __n: int) -> int: ...
def __xor__(self, __n: int) -> int: ...
@@ -317,11 +317,11 @@ class float:
def __mod__(self, __x: float) -> float: ...
def __divmod__(self, __x: float) -> tuple[float, float]: ...
@overload
def __pow__(self, __x: int, __mod: None = ...) -> float: ...
def __pow__(self, __x: int, __mod: None = None) -> float: ...
# positive x -> float; negative x -> complex
# return type must be Any as `float | complex` causes too many false-positive errors
@overload
def __pow__(self, __x: float, __mod: None = ...) -> Any: ...
def __pow__(self, __x: float, __mod: None = None) -> Any: ...
def __radd__(self, __x: float) -> float: ...
def __rsub__(self, __x: float) -> float: ...
def __rmul__(self, __x: float) -> float: ...
@@ -332,10 +332,10 @@ class float:
@overload
def __rpow__(self, __x: _PositiveInteger, __modulo: None = ...) -> float: ...
@overload
def __rpow__(self, __x: _NegativeInteger, __mod: None = ...) -> complex: ...
def __rpow__(self, __x: _NegativeInteger, __mod: None = None) -> complex: ...
# Returning `complex` for the general case gives too many false-positive errors.
@overload
def __rpow__(self, __x: float, __mod: None = ...) -> Any: ...
def __rpow__(self, __x: float, __mod: None = None) -> Any: ...
def __getnewargs__(self) -> tuple[float]: ...
def __trunc__(self) -> int: ...
if sys.version_info >= (3, 9):
@@ -343,7 +343,7 @@ class float:
def __floor__(self) -> int: ...
@overload
def __round__(self, __ndigits: None = ...) -> int: ...
def __round__(self, __ndigits: None = None) -> int: ...
@overload
def __round__(self, __ndigits: SupportsIndex) -> float: ...
def __eq__(self, __x: object) -> bool: ...
@@ -386,12 +386,12 @@ class complex:
def __add__(self, __x: complex) -> complex: ...
def __sub__(self, __x: complex) -> complex: ...
def __mul__(self, __x: complex) -> complex: ...
def __pow__(self, __x: complex, __mod: None = ...) -> complex: ...
def __pow__(self, __x: complex, __mod: None = None) -> complex: ...
def __truediv__(self, __x: complex) -> complex: ...
def __radd__(self, __x: complex) -> complex: ...
def __rsub__(self, __x: complex) -> complex: ...
def __rmul__(self, __x: complex) -> complex: ...
def __rpow__(self, __x: complex, __mod: None = ...) -> complex: ...
def __rpow__(self, __x: complex, __mod: None = None) -> complex: ...
def __rtruediv__(self, __x: complex) -> complex: ...
def __eq__(self, __x: object) -> bool: ...
def __ne__(self, __x: object) -> bool: ...
@@ -422,9 +422,9 @@ class str(Sequence[str]):
@overload
def casefold(self) -> str: ... # type: ignore[misc]
@overload
def center(self: LiteralString, __width: SupportsIndex, __fillchar: LiteralString = ...) -> LiteralString: ...
def center(self: LiteralString, __width: SupportsIndex, __fillchar: LiteralString = " ") -> LiteralString: ...
@overload
def center(self, __width: SupportsIndex, __fillchar: str = ...) -> str: ... # type: ignore[misc]
def center(self, __width: SupportsIndex, __fillchar: str = " ") -> str: ... # type: ignore[misc]
def count(self, x: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
def encode(self, encoding: str = "utf-8", errors: str = "strict") -> bytes: ...
def endswith(
@@ -465,27 +465,27 @@ class str(Sequence[str]):
@overload
def join(self, __iterable: Iterable[str]) -> str: ... # type: ignore[misc]
@overload
def ljust(self: LiteralString, __width: SupportsIndex, __fillchar: LiteralString = ...) -> LiteralString: ...
def ljust(self: LiteralString, __width: SupportsIndex, __fillchar: LiteralString = " ") -> LiteralString: ...
@overload
def ljust(self, __width: SupportsIndex, __fillchar: str = ...) -> str: ... # type: ignore[misc]
def ljust(self, __width: SupportsIndex, __fillchar: str = " ") -> str: ... # type: ignore[misc]
@overload
def lower(self: LiteralString) -> LiteralString: ...
@overload
def lower(self) -> str: ... # type: ignore[misc]
@overload
def lstrip(self: LiteralString, __chars: LiteralString | None = ...) -> LiteralString: ...
def lstrip(self: LiteralString, __chars: LiteralString | None = None) -> LiteralString: ...
@overload
def lstrip(self, __chars: str | None = ...) -> str: ... # type: ignore[misc]
def lstrip(self, __chars: str | None = None) -> str: ... # type: ignore[misc]
@overload
def partition(self: LiteralString, __sep: LiteralString) -> tuple[LiteralString, LiteralString, LiteralString]: ...
@overload
def partition(self, __sep: str) -> tuple[str, str, str]: ... # type: ignore[misc]
@overload
def replace(
self: LiteralString, __old: LiteralString, __new: LiteralString, __count: SupportsIndex = ...
self: LiteralString, __old: LiteralString, __new: LiteralString, __count: SupportsIndex = -1
) -> LiteralString: ...
@overload
def replace(self, __old: str, __new: str, __count: SupportsIndex = ...) -> str: ... # type: ignore[misc]
def replace(self, __old: str, __new: str, __count: SupportsIndex = -1) -> str: ... # type: ignore[misc]
if sys.version_info >= (3, 9):
@overload
def removeprefix(self: LiteralString, __prefix: LiteralString) -> LiteralString: ...
@@ -499,9 +499,9 @@ class str(Sequence[str]):
def rfind(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
def rindex(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
@overload
def rjust(self: LiteralString, __width: SupportsIndex, __fillchar: LiteralString = ...) -> LiteralString: ...
def rjust(self: LiteralString, __width: SupportsIndex, __fillchar: LiteralString = " ") -> LiteralString: ...
@overload
def rjust(self, __width: SupportsIndex, __fillchar: str = ...) -> str: ... # type: ignore[misc]
def rjust(self, __width: SupportsIndex, __fillchar: str = " ") -> str: ... # type: ignore[misc]
@overload
def rpartition(self: LiteralString, __sep: LiteralString) -> tuple[LiteralString, LiteralString, LiteralString]: ...
@overload
@@ -511,9 +511,9 @@ class str(Sequence[str]):
@overload
def rsplit(self, sep: str | None = None, maxsplit: SupportsIndex = -1) -> list[str]: ... # type: ignore[misc]
@overload
def rstrip(self: LiteralString, __chars: LiteralString | None = ...) -> LiteralString: ...
def rstrip(self: LiteralString, __chars: LiteralString | None = None) -> LiteralString: ...
@overload
def rstrip(self, __chars: str | None = ...) -> str: ... # type: ignore[misc]
def rstrip(self, __chars: str | None = None) -> str: ... # type: ignore[misc]
@overload
def split(self: LiteralString, sep: LiteralString | None = None, maxsplit: SupportsIndex = -1) -> list[LiteralString]: ...
@overload
@@ -526,9 +526,9 @@ class str(Sequence[str]):
self, __prefix: str | tuple[str, ...], __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...
) -> bool: ...
@overload
def strip(self: LiteralString, __chars: LiteralString | None = ...) -> LiteralString: ...
def strip(self: LiteralString, __chars: LiteralString | None = None) -> LiteralString: ...
@overload
def strip(self, __chars: str | None = ...) -> str: ... # type: ignore[misc]
def strip(self, __chars: str | None = None) -> str: ... # type: ignore[misc]
@overload
def swapcase(self: LiteralString) -> LiteralString: ...
@overload
@@ -633,9 +633,9 @@ class bytes(ByteString):
def join(self, __iterable_of_bytes: Iterable[ReadableBuffer]) -> bytes: ...
def ljust(self, __width: SupportsIndex, __fillchar: bytes | bytearray = ...) -> bytes: ...
def lower(self) -> bytes: ...
def lstrip(self, __bytes: ReadableBuffer | None = ...) -> bytes: ...
def lstrip(self, __bytes: ReadableBuffer | None = None) -> bytes: ...
def partition(self, __sep: ReadableBuffer) -> tuple[bytes, bytes, bytes]: ...
def replace(self, __old: ReadableBuffer, __new: ReadableBuffer, __count: SupportsIndex = ...) -> bytes: ...
def replace(self, __old: ReadableBuffer, __new: ReadableBuffer, __count: SupportsIndex = -1) -> bytes: ...
if sys.version_info >= (3, 9):
def removeprefix(self, __prefix: ReadableBuffer) -> bytes: ...
def removesuffix(self, __suffix: ReadableBuffer) -> bytes: ...
@@ -649,7 +649,7 @@ class bytes(ByteString):
def rjust(self, __width: SupportsIndex, __fillchar: bytes | bytearray = ...) -> bytes: ...
def rpartition(self, __sep: ReadableBuffer) -> tuple[bytes, bytes, bytes]: ...
def rsplit(self, sep: ReadableBuffer | None = None, maxsplit: SupportsIndex = -1) -> list[bytes]: ...
def rstrip(self, __bytes: ReadableBuffer | None = ...) -> bytes: ...
def rstrip(self, __bytes: ReadableBuffer | None = None) -> bytes: ...
def split(self, sep: ReadableBuffer | None = None, maxsplit: SupportsIndex = -1) -> list[bytes]: ...
def splitlines(self, keepends: bool = False) -> list[bytes]: ...
def startswith(
@@ -658,7 +658,7 @@ class bytes(ByteString):
__start: SupportsIndex | None = ...,
__end: SupportsIndex | None = ...,
) -> bool: ...
def strip(self, __bytes: ReadableBuffer | None = ...) -> bytes: ...
def strip(self, __bytes: ReadableBuffer | None = None) -> bytes: ...
def swapcase(self) -> bytes: ...
def title(self) -> bytes: ...
def translate(self, __table: ReadableBuffer | None, delete: bytes = ...) -> bytes: ...
@@ -740,15 +740,15 @@ class bytearray(MutableSequence[int], ByteString):
def join(self, __iterable_of_bytes: Iterable[ReadableBuffer]) -> bytearray: ...
def ljust(self, __width: SupportsIndex, __fillchar: bytes | bytearray = ...) -> bytearray: ...
def lower(self) -> bytearray: ...
def lstrip(self, __bytes: ReadableBuffer | None = ...) -> bytearray: ...
def lstrip(self, __bytes: ReadableBuffer | None = None) -> bytearray: ...
def partition(self, __sep: ReadableBuffer) -> tuple[bytearray, bytearray, bytearray]: ...
def pop(self, __index: int = ...) -> int: ...
def pop(self, __index: int = -1) -> int: ...
def remove(self, __value: int) -> None: ...
if sys.version_info >= (3, 9):
def removeprefix(self, __prefix: ReadableBuffer) -> bytearray: ...
def removesuffix(self, __suffix: ReadableBuffer) -> bytearray: ...
def replace(self, __old: ReadableBuffer, __new: ReadableBuffer, __count: SupportsIndex = ...) -> bytearray: ...
def replace(self, __old: ReadableBuffer, __new: ReadableBuffer, __count: SupportsIndex = -1) -> bytearray: ...
def rfind(
self, __sub: ReadableBuffer | SupportsIndex, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...
) -> int: ...
@@ -758,7 +758,7 @@ class bytearray(MutableSequence[int], ByteString):
def rjust(self, __width: SupportsIndex, __fillchar: bytes | bytearray = ...) -> bytearray: ...
def rpartition(self, __sep: ReadableBuffer) -> tuple[bytearray, bytearray, bytearray]: ...
def rsplit(self, sep: ReadableBuffer | None = None, maxsplit: SupportsIndex = -1) -> list[bytearray]: ...
def rstrip(self, __bytes: ReadableBuffer | None = ...) -> bytearray: ...
def rstrip(self, __bytes: ReadableBuffer | None = None) -> bytearray: ...
def split(self, sep: ReadableBuffer | None = None, maxsplit: SupportsIndex = -1) -> list[bytearray]: ...
def splitlines(self, keepends: bool = False) -> list[bytearray]: ...
def startswith(
@@ -767,7 +767,7 @@ class bytearray(MutableSequence[int], ByteString):
__start: SupportsIndex | None = ...,
__end: SupportsIndex | None = ...,
) -> bool: ...
def strip(self, __bytes: ReadableBuffer | None = ...) -> bytearray: ...
def strip(self, __bytes: ReadableBuffer | None = None) -> bytearray: ...
def swapcase(self) -> bytearray: ...
def title(self) -> bytearray: ...
def translate(self, __table: ReadableBuffer | None, delete: bytes = ...) -> bytearray: ...
@@ -932,7 +932,7 @@ class tuple(Sequence[_T_co], Generic[_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: SupportsIndex = ..., __stop: SupportsIndex = ...) -> int: ...
def index(self, __value: Any, __start: SupportsIndex = 0, __stop: SupportsIndex = sys.maxsize) -> int: ...
if sys.version_info >= (3, 9):
def __class_getitem__(cls, __item: Any) -> GenericAlias: ...
@@ -968,10 +968,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: SupportsIndex = ...) -> _T: ...
def pop(self, __index: SupportsIndex = -1) -> _T: ...
# Signature of `list.index` should be kept in line with `collections.UserList.index()`
# and multiprocessing.managers.ListProxy.index()
def index(self, __value: _T, __start: SupportsIndex = ..., __stop: SupportsIndex = ...) -> int: ...
def index(self, __value: _T, __start: SupportsIndex = 0, __stop: SupportsIndex = sys.maxsize) -> int: ...
def count(self, __value: _T) -> int: ...
def insert(self, __index: SupportsIndex, __object: _T) -> None: ...
def remove(self, __value: _T) -> None: ...
@@ -1043,7 +1043,7 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
# See #3800 & https://github.com/python/typing/issues/548#issuecomment-683336963.
@classmethod
@overload
def fromkeys(cls, __iterable: Iterable[_T], __value: None = ...) -> dict[_T, Any | None]: ...
def fromkeys(cls, __iterable: Iterable[_T], __value: None = None) -> dict[_T, Any | None]: ...
@classmethod
@overload
def fromkeys(cls, __iterable: Iterable[_T], __value: _S) -> dict[_T, _S]: ...
@@ -1323,15 +1323,17 @@ 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 | ReadableBuffer | CodeType, __globals: dict[str, Any] | None = ..., __locals: Mapping[str, object] | None = ...
__source: str | ReadableBuffer | CodeType,
__globals: dict[str, Any] | None = None,
__locals: Mapping[str, object] | None = None,
) -> Any: ...
# Comment above regarding `eval` applies to `exec` as well
if sys.version_info >= (3, 11):
def exec(
__source: str | ReadableBuffer | CodeType,
__globals: dict[str, Any] | None = ...,
__locals: Mapping[str, object] | None = ...,
__globals: dict[str, Any] | None = None,
__locals: Mapping[str, object] | None = None,
*,
closure: tuple[_Cell, ...] | None = None,
) -> None: ...
@@ -1339,8 +1341,8 @@ if sys.version_info >= (3, 11):
else:
def exec(
__source: str | ReadableBuffer | CodeType,
__globals: dict[str, Any] | None = ...,
__locals: Mapping[str, object] | None = ...,
__globals: dict[str, Any] | None = None,
__locals: Mapping[str, object] | None = None,
) -> None: ...
def exit(code: sys._ExitCode = None) -> NoReturn: ...
@@ -1355,7 +1357,7 @@ class filter(Iterator[_T], Generic[_T]):
def __iter__(self: Self) -> Self: ...
def __next__(self) -> _T: ...
def format(__value: object, __format_spec: str = ...) -> str: ...
def format(__value: object, __format_spec: str = "") -> str: ...
@overload
def getattr(__o: object, __name: str) -> Any: ...
@@ -1378,7 +1380,7 @@ def hash(__obj: object) -> int: ...
def help(request: object = ...) -> None: ...
def hex(__number: int | SupportsIndex) -> str: ...
def id(__obj: object) -> int: ...
def input(__prompt: object = ...) -> str: ...
def input(__prompt: object = None) -> str: ...
class _GetItemIterable(Protocol[_T_co]):
def __getitem__(self, __i: int) -> _T_co: ...
@@ -1728,7 +1730,7 @@ if sys.version_info >= (3, 8):
else:
@overload
def sum(__iterable: Iterable[bool | _LiteralInteger], __start: int = ...) -> int: ... # type: ignore[misc]
def sum(__iterable: Iterable[bool | _LiteralInteger], __start: int = 0) -> int: ... # type: ignore[misc]
@overload
def sum(__iterable: Iterable[_SupportsSumNoDefaultT]) -> _SupportsSumNoDefaultT | Literal[0]: ...