Skip to content

Add more defaults to the stdlib #9606

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 13 commits into from
Jan 29, 2023
36 changes: 18 additions & 18 deletions stdlib/_bisect.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,67 +8,67 @@ _T = TypeVar("_T")
if sys.version_info >= (3, 10):
@overload
def bisect_left(
a: Sequence[SupportsRichComparisonT], x: SupportsRichComparisonT, lo: int = ..., hi: int | None = ..., *, key: None = ...
a: Sequence[SupportsRichComparisonT], x: SupportsRichComparisonT, lo: int = 0, hi: int | None = None, *, key: None = None
) -> int: ...
@overload
def bisect_left(
a: Sequence[_T],
x: SupportsRichComparisonT,
lo: int = ...,
hi: int | None = ...,
lo: int = 0,
hi: int | None = None,
*,
key: Callable[[_T], SupportsRichComparisonT] = ...,
) -> int: ...
@overload
def bisect_right(
a: Sequence[SupportsRichComparisonT], x: SupportsRichComparisonT, lo: int = ..., hi: int | None = ..., *, key: None = ...
a: Sequence[SupportsRichComparisonT], x: SupportsRichComparisonT, lo: int = 0, hi: int | None = None, *, key: None = None
) -> int: ...
@overload
def bisect_right(
a: Sequence[_T],
x: SupportsRichComparisonT,
lo: int = ...,
hi: int | None = ...,
lo: int = 0,
hi: int | None = None,
*,
key: Callable[[_T], SupportsRichComparisonT] = ...,
) -> int: ...
@overload
def insort_left(
a: MutableSequence[SupportsRichComparisonT],
x: SupportsRichComparisonT,
lo: int = ...,
hi: int | None = ...,
lo: int = 0,
hi: int | None = None,
*,
key: None = ...,
key: None = None,
) -> None: ...
@overload
def insort_left(
a: MutableSequence[_T], x: _T, lo: int = ..., hi: int | None = ..., *, key: Callable[[_T], SupportsRichComparisonT] = ...
a: MutableSequence[_T], x: _T, lo: int = 0, hi: int | None = None, *, key: Callable[[_T], SupportsRichComparisonT] = ...
) -> None: ...
@overload
def insort_right(
a: MutableSequence[SupportsRichComparisonT],
x: SupportsRichComparisonT,
lo: int = ...,
hi: int | None = ...,
lo: int = 0,
hi: int | None = None,
*,
key: None = ...,
key: None = None,
) -> None: ...
@overload
def insort_right(
a: MutableSequence[_T], x: _T, lo: int = ..., hi: int | None = ..., *, key: Callable[[_T], SupportsRichComparisonT] = ...
a: MutableSequence[_T], x: _T, lo: int = 0, hi: int | None = None, *, key: Callable[[_T], SupportsRichComparisonT] = ...
) -> None: ...

else:
def bisect_left(
a: Sequence[SupportsRichComparisonT], x: SupportsRichComparisonT, lo: int = ..., hi: int | None = ...
a: Sequence[SupportsRichComparisonT], x: SupportsRichComparisonT, lo: int = 0, hi: int | None = None
) -> int: ...
def bisect_right(
a: Sequence[SupportsRichComparisonT], x: SupportsRichComparisonT, lo: int = ..., hi: int | None = ...
a: Sequence[SupportsRichComparisonT], x: SupportsRichComparisonT, lo: int = 0, hi: int | None = None
) -> int: ...
def insort_left(
a: MutableSequence[SupportsRichComparisonT], x: SupportsRichComparisonT, lo: int = ..., hi: int | None = ...
a: MutableSequence[SupportsRichComparisonT], x: SupportsRichComparisonT, lo: int = 0, hi: int | None = None
) -> None: ...
def insort_right(
a: MutableSequence[SupportsRichComparisonT], x: SupportsRichComparisonT, lo: int = ..., hi: int | None = ...
a: MutableSequence[SupportsRichComparisonT], x: SupportsRichComparisonT, lo: int = 0, hi: int | None = None
) -> None: ...
2 changes: 1 addition & 1 deletion stdlib/_bootlocale.pyi
Original file line number Diff line number Diff line change
@@ -1 +1 @@
def getpreferredencoding(do_setlocale: bool = ...) -> str: ...
def getpreferredencoding(do_setlocale: bool = True) -> str: ...
18 changes: 10 additions & 8 deletions stdlib/_codecs.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,29 @@ _BytesToBytesEncoding: TypeAlias = Literal[
_StrToStrEncoding: TypeAlias = Literal["rot13", "rot_13"]

@overload
def encode(obj: ReadableBuffer, encoding: _BytesToBytesEncoding, errors: str = ...) -> bytes: ...
def encode(obj: ReadableBuffer, encoding: _BytesToBytesEncoding, errors: str = "strict") -> bytes: ...
@overload
def encode(obj: str, encoding: _StrToStrEncoding, errors: str = ...) -> str: ... # type: ignore[misc]
def encode(obj: str, encoding: _StrToStrEncoding, errors: str = "strict") -> str: ... # type: ignore[misc]
@overload
def encode(obj: str, encoding: str = ..., errors: str = ...) -> bytes: ...
def encode(obj: str, encoding: str = "utf-8", errors: str = "strict") -> bytes: ...
@overload
def decode(obj: ReadableBuffer, encoding: _BytesToBytesEncoding, errors: str = ...) -> bytes: ... # type: ignore[misc]
def decode(obj: ReadableBuffer, encoding: _BytesToBytesEncoding, errors: str = "strict") -> bytes: ... # type: ignore[misc]
@overload
def decode(obj: str, encoding: _StrToStrEncoding, errors: str = ...) -> str: ...
def decode(obj: str, encoding: _StrToStrEncoding, errors: str = "strict") -> str: ...

# these are documented as text encodings but in practice they also accept str as input
@overload
def decode(
obj: str, encoding: Literal["unicode_escape", "unicode-escape", "raw_unicode_escape", "raw-unicode-escape"], errors: str = ...
obj: str,
encoding: Literal["unicode_escape", "unicode-escape", "raw_unicode_escape", "raw-unicode-escape"],
errors: str = "strict",
) -> str: ...

# hex is officially documented as a bytes to bytes encoding, but it appears to also work with str
@overload
def decode(obj: str, encoding: Literal["hex", "hex_codec"], errors: str = ...) -> bytes: ...
def decode(obj: str, encoding: Literal["hex", "hex_codec"], errors: str = "strict") -> bytes: ...
@overload
def decode(obj: ReadableBuffer, encoding: str = ..., errors: str = ...) -> str: ...
def decode(obj: ReadableBuffer, encoding: str = "utf-8", errors: str = "strict") -> str: ...
def lookup(__encoding: str) -> codecs.CodecInfo: ...
def charmap_build(__map: str) -> _CharMap: ...
def ascii_decode(__data: ReadableBuffer, __errors: str | None = ...) -> tuple[str, int]: ...
Expand Down
2 changes: 1 addition & 1 deletion stdlib/_decimal.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ if sys.version_info >= (3, 11):
) -> _ContextManager: ...

else:
def localcontext(ctx: Context | None = ...) -> _ContextManager: ...
def localcontext(ctx: Context | None = None) -> _ContextManager: ...

class Decimal:
def __new__(cls: type[Self], value: _DecimalNew = ..., context: Context | None = ...) -> Self: ...
Expand Down
6 changes: 3 additions & 3 deletions stdlib/_dummy_thread.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ def start_new_thread(function: Callable[..., object], args: tuple[Any, ...], kwa
def exit() -> NoReturn: ...
def get_ident() -> int: ...
def allocate_lock() -> LockType: ...
def stack_size(size: int | None = ...) -> int: ...
def stack_size(size: int | None = None) -> int: ...

class LockType:
locked_status: bool
def acquire(self, waitflag: bool | None = ..., timeout: int = ...) -> bool: ...
def __enter__(self, waitflag: bool | None = ..., timeout: int = ...) -> bool: ...
def acquire(self, waitflag: bool | None = None, timeout: int = -1) -> bool: ...
def __enter__(self, waitflag: bool | None = None, timeout: int = -1) -> bool: ...
def __exit__(self, typ: type[BaseException] | None, val: BaseException | None, tb: TracebackType | None) -> None: ...
def release(self) -> bool: ...
def locked(self) -> bool: ...
Expand Down
38 changes: 19 additions & 19 deletions stdlib/_dummy_threading.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,17 @@ class Thread:
def ident(self) -> int | None: ...
def __init__(
self,
group: None = ...,
target: Callable[..., object] | None = ...,
name: str | None = ...,
group: None = None,
target: Callable[..., object] | None = None,
name: str | None = None,
args: Iterable[Any] = ...,
kwargs: Mapping[str, Any] | None = ...,
kwargs: Mapping[str, Any] | None = None,
*,
daemon: bool | None = ...,
daemon: bool | None = None,
) -> None: ...
def start(self) -> None: ...
def run(self) -> None: ...
def join(self, timeout: float | None = ...) -> None: ...
def join(self, timeout: float | None = None) -> None: ...
def getName(self) -> str: ...
def setName(self, name: str) -> None: ...
if sys.version_info >= (3, 8):
Expand Down Expand Up @@ -99,32 +99,32 @@ class _RLock:
def __exit__(
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
) -> bool | None: ...
def acquire(self, blocking: bool = ..., timeout: float = ...) -> bool: ...
def acquire(self, blocking: bool = True, timeout: float = -1) -> bool: ...
def release(self) -> None: ...

RLock = _RLock

class Condition:
def __init__(self, lock: Lock | _RLock | None = ...) -> None: ...
def __init__(self, lock: Lock | _RLock | None = None) -> None: ...
def __enter__(self) -> bool: ...
def __exit__(
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
) -> bool | None: ...
def acquire(self, blocking: bool = ..., timeout: float = ...) -> bool: ...
def release(self) -> None: ...
def wait(self, timeout: float | None = ...) -> bool: ...
def wait_for(self, predicate: Callable[[], _T], timeout: float | None = ...) -> _T: ...
def notify(self, n: int = ...) -> None: ...
def wait(self, timeout: float | None = None) -> bool: ...
def wait_for(self, predicate: Callable[[], _T], timeout: float | None = None) -> _T: ...
def notify(self, n: int = 1) -> None: ...
def notify_all(self) -> None: ...
def notifyAll(self) -> None: ...

class Semaphore:
def __init__(self, value: int = ...) -> None: ...
def __init__(self, value: int = 1) -> None: ...
def __exit__(
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
) -> bool | None: ...
def acquire(self, blocking: bool = ..., timeout: float | None = ...) -> bool: ...
def __enter__(self, blocking: bool = ..., timeout: float | None = ...) -> bool: ...
def acquire(self, blocking: bool = True, timeout: float | None = None) -> bool: ...
def __enter__(self, blocking: bool = True, timeout: float | None = None) -> bool: ...
if sys.version_info >= (3, 9):
def release(self, n: int = ...) -> None: ...
else:
Expand All @@ -136,7 +136,7 @@ class Event:
def is_set(self) -> bool: ...
def set(self) -> None: ...
def clear(self) -> None: ...
def wait(self, timeout: float | None = ...) -> bool: ...
def wait(self, timeout: float | None = None) -> bool: ...

if sys.version_info >= (3, 8):
from _thread import _excepthook, _ExceptHookArgs
Expand All @@ -149,8 +149,8 @@ class Timer(Thread):
self,
interval: float,
function: Callable[..., object],
args: Iterable[Any] | None = ...,
kwargs: Mapping[str, Any] | None = ...,
args: Iterable[Any] | None = None,
kwargs: Mapping[str, Any] | None = None,
) -> None: ...
def cancel(self) -> None: ...

Expand All @@ -161,8 +161,8 @@ class Barrier:
def n_waiting(self) -> int: ...
@property
def broken(self) -> bool: ...
def __init__(self, parties: int, action: Callable[[], None] | None = ..., timeout: float | None = ...) -> None: ...
def wait(self, timeout: float | None = ...) -> int: ...
def __init__(self, parties: int, action: Callable[[], None] | None = None, timeout: float | None = None) -> None: ...
def wait(self, timeout: float | None = None) -> int: ...
def reset(self) -> None: ...
def abort(self) -> None: ...

Expand Down
4 changes: 2 additions & 2 deletions stdlib/_warnings.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ _onceregistry: dict[Any, Any]
filters: list[tuple[str, str | None, type[Warning], str | None, int]]

@overload
def warn(message: str, category: type[Warning] | None = ..., stacklevel: int = ..., source: Any | None = ...) -> None: ...
def warn(message: str, category: type[Warning] | None = None, stacklevel: int = 1, source: Any | None = None) -> None: ...
@overload
def warn(message: Warning, category: Any = ..., stacklevel: int = ..., source: Any | None = ...) -> None: ...
def warn(message: Warning, category: Any = None, stacklevel: int = 1, source: Any | None = None) -> None: ...
@overload
def warn_explicit(
message: str,
Expand Down
2 changes: 1 addition & 1 deletion stdlib/_weakrefset.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ _T = TypeVar("_T")

class WeakSet(MutableSet[_T], Generic[_T]):
@overload
def __init__(self, data: None = ...) -> None: ...
def __init__(self, data: None = None) -> None: ...
@overload
def __init__(self, data: Iterable[_T]) -> None: ...
def add(self, item: _T) -> None: ...
Expand Down
6 changes: 3 additions & 3 deletions stdlib/_winapi.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ if sys.platform == "win32":
@overload
def ConnectNamedPipe(handle: int, overlapped: Literal[True]) -> Overlapped: ...
@overload
def ConnectNamedPipe(handle: int, overlapped: Literal[False] = ...) -> None: ...
def ConnectNamedPipe(handle: int, overlapped: Literal[False] = False) -> None: ...
@overload
def ConnectNamedPipe(handle: int, overlapped: bool) -> Overlapped | None: ...
def CreateFile(
Expand Down Expand Up @@ -189,7 +189,7 @@ if sys.platform == "win32":
@overload
def ReadFile(handle: int, size: int, overlapped: Literal[True]) -> tuple[Overlapped, int]: ...
@overload
def ReadFile(handle: int, size: int, overlapped: Literal[False] = ...) -> tuple[bytes, int]: ...
def ReadFile(handle: int, size: int, overlapped: Literal[False] = False) -> tuple[bytes, int]: ...
@overload
def ReadFile(handle: int, size: int, overlapped: int | bool) -> tuple[Any, int]: ...
def SetNamedPipeHandleState(
Expand All @@ -202,7 +202,7 @@ if sys.platform == "win32":
@overload
def WriteFile(handle: int, buffer: ReadableBuffer, overlapped: Literal[True]) -> tuple[Overlapped, int]: ...
@overload
def WriteFile(handle: int, buffer: ReadableBuffer, overlapped: Literal[False] = ...) -> tuple[int, int]: ...
def WriteFile(handle: int, buffer: ReadableBuffer, overlapped: Literal[False] = False) -> tuple[int, int]: ...
@overload
def WriteFile(handle: int, buffer: ReadableBuffer, overlapped: int | bool) -> tuple[Any, int]: ...
@final
Expand Down
4 changes: 2 additions & 2 deletions stdlib/aifc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ def open(f: _File, mode: Literal["r", "rb"]) -> Aifc_read: ...
@overload
def open(f: _File, mode: Literal["w", "wb"]) -> Aifc_write: ...
@overload
def open(f: _File, mode: str | None = ...) -> Any: ...
def open(f: _File, mode: str | None = None) -> Any: ...

if sys.version_info < (3, 9):
@overload
def openfp(f: _File, mode: Literal["r", "rb"]) -> Aifc_read: ...
@overload
def openfp(f: _File, mode: Literal["w", "wb"]) -> Aifc_write: ...
@overload
def openfp(f: _File, mode: str | None = ...) -> Any: ...
def openfp(f: _File, mode: str | None = None) -> Any: ...
38 changes: 19 additions & 19 deletions stdlib/argparse.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -148,23 +148,23 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
else:
def __init__(
self,
prog: str | None = ...,
usage: str | None = ...,
description: str | None = ...,
epilog: str | None = ...,
prog: str | None = None,
usage: str | None = None,
description: str | None = None,
epilog: str | None = None,
parents: Sequence[ArgumentParser] = ...,
formatter_class: _FormatterClass = ...,
prefix_chars: str = ...,
fromfile_prefix_chars: str | None = ...,
argument_default: Any = ...,
conflict_handler: str = ...,
add_help: bool = ...,
allow_abbrev: bool = ...,
prefix_chars: str = "-",
fromfile_prefix_chars: str | None = None,
argument_default: Any = None,
conflict_handler: str = "error",
add_help: bool = True,
allow_abbrev: bool = True,
) -> None: ...
# The type-ignores in these overloads should be temporary. See:
# https://github.com/python/typeshed/pull/2643#issuecomment-442280277
@overload
def parse_args(self, args: Sequence[str] | None = ...) -> Namespace: ...
def parse_args(self, args: Sequence[str] | None = None) -> Namespace: ...
@overload
def parse_args(self, args: Sequence[str] | None, namespace: None) -> Namespace: ... # type: ignore[misc]
@overload
Expand Down Expand Up @@ -378,10 +378,10 @@ class _StoreConstAction(Action):
option_strings: Sequence[str],
dest: str,
const: Any,
default: Any = ...,
required: bool = ...,
help: str | None = ...,
metavar: str | tuple[str, ...] | None = ...,
default: Any = None,
required: bool = False,
help: str | None = None,
metavar: str | tuple[str, ...] | None = None,
) -> None: ...

# undocumented
Expand Down Expand Up @@ -422,10 +422,10 @@ class _AppendConstAction(Action):
option_strings: Sequence[str],
dest: str,
const: Any,
default: Any = ...,
required: bool = ...,
help: str | None = ...,
metavar: str | tuple[str, ...] | None = ...,
default: Any = None,
required: bool = False,
help: str | None = None,
metavar: str | tuple[str, ...] | None = None,
) -> None: ...

# undocumented
Expand Down
Loading