8000 Add more defaults to the stdlib (#9606) · python/typeshed@33a62ae · GitHub
[go: up one dir, main page]

Skip to content

Commit 33a62ae

Browse files
authored
Add more defaults to the stdlib (#9606)
Continuing work towards #8988. The first five commits were created using stubdefaulter on various Python versions; the following commits were all created manually by me to fix various problems. The main things this adds that weren't present in #9501 are: - Defaults in Windows-only modules and Windows-only branches (because I'm running a Windows machine) - Defaults in non-py311 branches - Defaults for float parameters - Defaults for overloads
1 parent 25e02db commit 33a62ae

File tree

150 files changed

+2761
-2704
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+2761
-2704
lines changed

stdlib/_bisect.pyi

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,67 +8,67 @@ _T = TypeVar("_T")
88
if sys.version_info >= (3, 10):
99
@overload
1010
def bisect_left(
11-
a: Sequence[SupportsRichComparisonT], x: SupportsRichComparisonT, lo: int = ..., hi: int | None = ..., *, key: None = ...
11+
a: Sequence[SupportsRichComparisonT], x: SupportsRichComparisonT, lo: int = 0, hi: int | None = None, *, key: None = None
1212
) -> int: ...
1313
@overload
1414
def bisect_left(
1515
a: Sequence[_T],
1616
x: SupportsRichComparisonT,
17-
lo: int = ...,
18-
hi: int | None = ...,
17+
lo: int = 0,
18+
hi: int | None = None,
1919
*,
2020
key: Callable[[_T], SupportsRichComparisonT] = ...,
2121
) -> int: ...
2222
@overload
2323
def bisect_right(
24-
a: Sequence[SupportsRichComparisonT], x: SupportsRichComparisonT, lo: int = ..., hi: int | None = ..., *, key: None = ...
24+
a: Sequence[SupportsRichComparisonT], x: SupportsRichComparisonT, lo: int = 0, hi: int | None = None, *, key: None = None
2525
) -> int: ...
2626
@overload
2727
def bisect_right(
2828
a: Sequence[_T],
2929
x: SupportsRichComparisonT,
30-
lo: int = ...,
31-
hi: int | None = ...,
30+
lo: int = 0,
31+
hi: int | None = None,
3232
*,
3333
key: Callable[[_T], SupportsRichComparisonT] = ...,
3434
) -> int: ...
3535
@overload
3636
def insort_left(
3737
a: MutableSequence[SupportsRichComparisonT],
3838
x: SupportsRichComparisonT,
39-
lo: int = ...,
40-
hi: int | None = ...,
39+
lo: int = 0,
40+
hi: int | None = None,
4141
*,
42-
key: None = ...,
42+
key: None = None,
4343
) -> None: ...
4444
@overload
4545
def insort_left(
46-
a: MutableSequence[_T], x: _T, lo: int = ..., hi: int | None = ..., *, key: Callable[[_T], SupportsRichComparisonT] = ...
46+
a: MutableSequence[_T], x: _T, lo: int = 0, 10000 hi: int | None = None, *, key: Callable[[_T], SupportsRichComparisonT] = ...
4747
) -> None: ...
4848
@overload
4949
def insort_right(
5050
a: MutableSequence[SupportsRichComparisonT],
5151
x: SupportsRichComparisonT,
52-
lo: int = ...,
53-
hi: int | None = ...,
52+
lo: int = 0,
53+
hi: int | None = None,
5454
*,
55-
key: None = ...,
55+
key: None = None,
5656
) -> None: ...
5757
@overload
5858
def insort_right(
59-
a: MutableSequence[_T], x: _T, lo: int = ..., hi: int | None = ..., *, key: Callable[[_T], SupportsRichComparisonT] = ...
59+
a: MutableSequence[_T], x: _T, lo: int = 0, hi: int | None = None, *, key: Callable[[_T], SupportsRichComparisonT] = ...
6060
) -> None: ...
6161

6262
else:
6363
def bisect_left(
64-
a: Sequence[SupportsRichComparisonT], x: SupportsRichComparisonT, lo: int = ..., hi: int | None = ...
64+
a: Sequence[SupportsRichComparisonT], x: SupportsRichComparisonT, lo: int = 0, hi: int | None = None
6565
) -> int: ...
6666
def bisect_right(
67-
a: Sequence[SupportsRichComparisonT], x: SupportsRichComparisonT, lo: int = ..., hi: int | None = ...
67+
a: Sequence[SupportsRichComparisonT], x: SupportsRichComparisonT, lo: int = 0, hi: int | None = None
6868
) -> int: ...
6969
def insort_left(
70-
a: MutableSequence[SupportsRichComparisonT], x: SupportsRichComparisonT, lo: int = ..., hi: int | None = ...
70+
a: MutableSequence[SupportsRichComparisonT], x: SupportsRichComparisonT, lo: int = 0, hi: int | None = None
7171
) -> None: ...
7272
def insort_right(
73-
a: MutableSequence[SupportsRichComparisonT], x: SupportsRichComparisonT, lo: int = ..., hi: int | None = ...
73+
a: MutableSequence[SupportsRichComparisonT], x: SupportsRichComparisonT, lo: int = 0, hi: int | None = None
7474
) -> None: ...

stdlib/_bootlocale.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
def getpreferredencoding(do_setlocale: bool = ...) -> str: ...
1+
def getpreferredencoding(do_setlocale: bool = True) -> str: ...

< C2EE code>‎stdlib/_codecs.pyi

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,27 +45,29 @@ _BytesToBytesEncoding: TypeAlias = Literal[
4545
_StrToStrEncoding: TypeAlias = Literal["rot13", "rot_13"]
4646

4747
@overload
48-
def encode(obj: ReadableBuffer, encoding: _BytesToBytesEncoding, errors: str = ...) -> bytes: ...
48+
def encode(obj: ReadableBuffer, encoding: _BytesToBytesEncoding, errors: str = "strict") -> bytes: ...
4949
@overload
50-
def encode(obj: str, encoding: _StrToStrEncoding, errors: str = ...) -> str: ... # type: ignore[misc]
50+
def encode(obj: str, encoding: _StrToStrEncoding, errors: str = "strict") -> str: ... # type: ignore[misc]
5151
@overload
52-
def encode(obj: str, encoding: str = ..., errors: str = ...) -> bytes: ...
52+
def encode(obj: str, encoding: str = "utf-8", errors: str = "strict") -> bytes: ...
5353
@overload
54-
def decode(obj: ReadableBuffer, encoding: _BytesToBytesEncoding, errors: str = ...) -> bytes: ... # type: ignore[misc]
54+
def decode(obj: ReadableBuffer, encoding: _BytesToBytesEncoding, errors: str = "strict") -> bytes: ... # type: ignore[misc]
5555
@overload
56-
def decode(obj: str, encoding: _StrToStrEncoding, errors: str = ...) -> str: ...
56+
def decode(obj: str, encoding: _StrToStrEncoding, errors: str = "strict") -> str: ...
5757

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

6466
# hex is officially documented as a bytes to bytes encoding, but it appears to also work with str
6567
@overload
66-
def decode(obj: str, encoding: Literal["hex", "hex_codec"], errors: str = ...) -> bytes: ...
68+
def decode(obj: str, encoding: Literal["hex", "hex_codec"], errors: str = "strict") -> bytes: ...
6769
@overload
68-
def decode(obj: ReadableBuffer, encoding: str = ..., errors: str = ...) -> str: ...
70+
def decode(obj: ReadableBuffer, encoding: str = "utf-8", errors: str = "strict") -> str: ...
6971
def lookup(__encoding: str) -> codecs.CodecInfo: ...
7072
def charmap_build(__map: str) -> _CharMap: ...
7173
def ascii_decode(__data: ReadableBuffer, __errors: str | None = ...) -> tuple[str, int]: ...

stdlib/_decimal.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ if sys.version_info >= (3, 11):
6666
) -> _ContextManager: ...
6767

6868
else:
69-
def localcontext(ctx: Context | None = ...) -> _ContextManager: ...
69+
def localcontext(ctx: Context | None = None) -> _ContextManager: ...
7070

7171
class Decimal:
7272
def __new__(cls: type[Self], value: _DecimalNew = ..., context: Context | None = ...) -> Self: ...

stdlib/_dummy_thread.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ def start_new_thread(function: Callable[..., object], args: tuple[Any, ...], kwa
1111
def exit() -> NoReturn: ...
1212
def get_ident() -> int: ...
1313
def allocate_lock() -> LockType: ...
14-
def stack_size(size: int | None = ...) -> int: ...
14+
def stack_size(size: int | None = None) -> int: ...
1515

1616
class LockType:
1717
locked_status: bool
18-
def acquire(self, waitflag: bool | None = ..., timeout: int = ...) -> bool: ...
19-
def __enter__(self, waitflag: bool | None = ..., timeout: int = ...) -> bool: ...
18+
def acquire(self, waitflag: bool | None = None, timeout: int = -1) -> bool: ...
19+
def __enter__(self, waitflag: bool | None = None, timeout: int = -1) -> bool: ...
2020
def __exit__(self, typ: type[BaseException] | None, val: BaseException | None, tb: TracebackType | None) -> None: ...
2121
def release(self) -> bool: ...
2222
def locked(self) -> bool: ...

stdlib/_dummy_threading.pyi

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,17 @@ class Thread:
5959
def ident(self) -> int | None: ...
6060
def __init__(
6161
self,
62-
group: None = ...,
63-
target: Callable[..., object] | None = ...,
64-
name: str | None = ...,
62+
group: None = None,
63+
target: Callable[..., object] | None = None,
64+
name: str | None = None,
6565
args: Iterable[Any] = ...,
66-
kwargs: Mapping[str, Any] | None = ...,
66+
kwargs: Mapping[str, Any] | None = None,
6767
*,
68-
daemon: bool | None = ...,
68+
daemon: bool | None = None,
6969
) -> None: ...
7070
def start(self) -> None: ...
7171
def run(self) -> None: ...
72-
def join(self, timeout: float | None = ...) -> None: ...
72+
def join(self, timeout: float | None = None) -> None: ...
7373
def getName(self) -> str: ...
7474
def setName(self, name: str) -> None: ...
7575
if sys.version_info >= (3, 8):
@@ -99,32 +99,32 @@ class _RLock:
9999
def __exit__(
100100
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
101101
) -> bool | None: ...
102-
def acquire(self, blocking: bool = ..., timeout: float = ...) -> bool: ...
102+
def acquire(self, blocking: bool = True, timeout: float = -1) -> bool: ...
103103
def release(self) -> None: ...
104104

105105
RLock = _RLock
106106

107107
class Condition:
108-
def __init__(self, lock: Lock | _RLock | None = ...) -> None: ...
108+
def __init__(self, lock: Lock | _RLock | None = None) -> None: ...
109109
def __enter__(self) -> bool: ...
110110
def __exit__(
111111
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
112112
) -> bool | None: ...
113113
def acquire(self, blocking: bool = ..., timeout: float = ...) -> bool: ...
114114
def release(self) -> None: ...
115-
def wait(self, timeout: float | None = ...) -> bool: ...
116-
def wait_for(self, predicate: Callable[[], _T], timeout: float | None = ...) -> _T: ...
117-
def notify(self, n: int = ...) -> None: ...
115+
def wait(self, timeout: float | None = None) -> bool: ...
116+
def wait_for(self, predicate: Callable[[], _T], timeout: float | None = None) -> _T: ...
117+
def notify(self, n: int = 1) -> None: ...
118118
def notify_all(self) -> None: ...
119119
def notifyAll(self) -> None: ...
120120

121121
class Semaphore:
122-
def __init__(self, value: int = ...) -> None: ...
122+
def __init__(self, value: int = 1) -> None: ...
123123
def __exit__(
124124
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
125125
) -> bool | None: ...
126-
def acquire(self, blocking: bool = ..., timeout: float | None = ...) -> bool: ...
127-
def __enter__(self, blocking: bool = ..., timeout: float | None = ...) -> bool: ...
126+
def acquire(self, blocking: bool = True, timeout: float | None = None) -> bool: ...
127+
def __enter__(self, blocking: bool = True, timeout: float | None = None) -> bool: ...
128128
if sys.version_info >= (3, 9):
129129
def release(self, n: int = ...) -> None: ...
130130
else:
@@ -136,7 +136,7 @@ class Event:
136136
def is_set(self) -> bool: ...
137137
def set(self) -> None: ...
138138
def clear(self) -> None: ...
139-
def wait(self, timeout: float | None = ...) -> bool: ...
139+
def wait(self, timeout: float | None = None) -> bool: ...
140140

141141
if sys.version_info >= (3, 8):
142142
from _thread import _excepthook, _ExceptHookArgs
@@ -149,8 +149,8 @@ class Timer(Thread):
149149
self,
150150
interval: float,
151151
function: Callable[..., object],
152-
args: Iterable[Any] | None = ...,
153-
kwargs: Mapping[str, Any] | None = ...,
152+
args: Iterable[Any] | None = None,
153+
kwargs: Mapping[str, Any] | None = None,
154154
) -> None: ...
155155
def cancel(self) -> None: ...
156156

@@ -161,8 +161,8 @@ class Barrier:
161161
def n_waiting(self) -> int: ...
162162
@property
163163
def broken(self) -> bool: ...
164-
def __init__(self, parties: int, action: Callable[[], None] | None = ..., timeout: float | None = ...) -> None: ...
165-
def wait(self, timeout: float | None = ...) -> int: ...
164+
def __init__(self, parties: int, action: Callable[[], None] | None = None, timeout: float | None = None) -> None: ...
165+
def wait(self, timeout: float | None = None) -> int: ...
166166
def reset(self) -> None: ...
167167
def abort(self) -> None: ...
168168

stdlib/_warnings.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ _onceregistry: dict[Any, Any]
55
filters: list[tuple[str, str | None, type[Warning], str | None, int]]
66

77
@overload
8-
def warn(message: str, category: type[Warning] | None = ..., stacklevel: int = ..., source: Any | None = ...) -> None: ...
8+
def warn(message: str, category: type[Warning] | None = None, stacklevel: int = 1, source: Any | None = None) -> None: ...
99
@overload
10-
def warn(message: Warning, category: Any = ..., stacklevel: int = ..., source: Any | None = ...) -> None: ...
10+
def warn(message: Warning, category: Any = None, stacklevel: int = 1, source: Any | None = None) -> None: ...
1111
@overload
1212
def warn_explicit(
1313
message: str,

stdlib/_weakrefset.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ _T = TypeVar("_T")
1313

1414
class WeakSet(MutableSet[_T], Generic[_T]):
1515
@overload
16-
def __init__(self, data: None = ...) -> None: ...
16+
def __init__(self, data: None = None) -> None: ...
1717
@overload
1818
def __init__(self, data: Iterable[_T]) -> None: ...
1919
def add(self, item: _T) -> None: ...

stdlib/_winapi.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ if sys.platform == "win32":
128128
@overload
129129
def ConnectNamedPipe(handle: int, overlapped: Literal[True]) -> Overlapped: ...
130130
@overload
131-
def ConnectNamedPipe(handle: int, overlapped: Literal[False] = ...) -> None: ...
131+
def ConnectNamedPipe(handle: int, overlapped: Literal[False] = False) -> None: ...
132132
@overload
133133
def ConnectNamedPipe(handle: int, overlapped: bool) -> Overlapped | None: ...
134134
def CreateFile(
@@ -189,7 +189,7 @@ if sys.platform == "win32":
189189
@overload
190190
def ReadFile(handle: int, size: int, overlapped: Literal[True]) -> tuple[Overlapped, int]: ...
191191
@overload
192-
def ReadFile(handle: int, size: int, overlapped: Literal[False] = ...) -> tuple[bytes, int]: ...
192+
def ReadFile(handle: int, size: int, overlapped: Literal[False] = False) -> tuple[bytes, int]: ...
193193
@overload
194194
def ReadFile(handle: int, size: int, overlapped: int | bool) -> tuple[Any, int]: ...
195195
def SetNamedPipeHandleState(
@@ -202,7 +202,7 @@ if sys.platform == "win32":
202202
@overload
203203
def WriteFile(handle: int, buffer: ReadableBuffer, overlapped: Literal[True]) -> tuple[Overlapped, int]: ...
204204
@overload
205-
def WriteFile(handle: int, buffer: ReadableBuffer, overlapped: Literal[False] = ...) -> tuple[int, int]: ...
205+
def WriteFile(handle: int, buffer: ReadableBuffer, overlapped: Literal[False] = False) -> tuple[int, int]: ...
206206
@overload
207207
def WriteFile(handle: int, buffer: ReadableBuffer, overlapped: int | bool) -> tuple[Any, int]: ...
208208
@final

stdlib/aifc.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ def open(f: _File, mode: Literal["r", "rb"]) -> Aifc_read: ...
8181
@overload
8282
def open(f: _File, mode: Literal["w", "wb"]) -> Aifc_write: ...
8383
@overload
84-
def open(f: _File, mode: str | None = ...) -> Any: ...
84+
def open(f: _File, mode: str | None = None) -> Any: ...
8585

8686
if sys.version_info < (3, 9):
8787
@overload
8888
def openfp(f: _File, mode: Literal["r", "rb"]) -> Aifc_read: ...
8989
@o 10000 verload
9090
def openfp(f: _File, mode: Literal["w", "wb"]) -> Aifc_write: ...
9191
@overload
92-
def openfp(f: _File, mode: str | None = ...) -> Any: ...
92+
def openfp(f: _File, mode: str | None = None) -> Any: ...

stdlib/argparse.pyi

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -148,23 +148,23 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
148148
else:
149149
def __init__(
150150
self,
151-
prog: str | None = ...,
152-
usage: str | None = ...,
153-
description: str | None = ...,
154-
epilog: str | None = ...,
151+
prog: str | None = None,
152+
usage: str | None = None,
153+
description: str | None = None,
154+
epilog: str | None = None,
155155
parents: Sequence[ArgumentParser] = ...,
156156
formatter_class: _FormatterClass = ...,
157-
prefix_chars: str = ...,
158-
fromfile_prefix_chars: str | None = ...,
159-
argument_default: Any = ...,
160-
conflict_handler: str = ...,
161-
add_help: bool = ...,
162-
allow_abbrev: bool = ...,
157+
prefix_chars: str = "-",
158+
fromfile_prefix_chars: str | None = None,
159+
argument_default: Any = None,
160+
conflict_handler: str = "error",
161+
add_help: bool = True,
162+
allow_abbrev: bool = True,
163163
) -> None: ...
164164
# The type-ignores in these overloads should be temporary. See:
165165
# https://github.com/python/typeshed/pull/2643#issuecomment-442280277
166166
@overload
167-
def parse_args(self, args: Sequence[str] | None = ...) -> Namespace: ...
167+
def parse_args(self, args: Sequence[str] | None = None) -> Namespace: ...
168168
@overload
169169
def parse_args(self, args: Sequence[str] | None, namespace: None) -> Namespace: ... # type: ignore[misc]
170170
@overload
@@ -378,10 +378,10 @@ class _StoreConstAction(Action):
378378
option_strings: Sequence[str],
379379
dest: str,
380380
const: Any,
381-
default: Any = ...,
382-
required: bool = ...,
383-
help: str | None = ...,
384-
metavar: str | tuple[str, ...] | None = ...,
381+
default: Any = None,
382+
required: bool = False,
383+
help: str | None = None,
384+
metavar: str | tuple[str, ...] | None = None,
385385
) -> None: ...
386386

387387
# undocumented
@@ -422,10 +422,10 @@ class _AppendConstAction(Action):
422422
option_strings: Sequence[str],
423423
dest: str,
424424
const: Any,
425-
default: Any = ...,
426-
required: bool = ...,
427-
help: str | None = ...,
428-
metavar: str | tuple[str, ...] | None = ...,
425+
default: Any = None,
426+
required: bool = False,
427+
help: str | None = None,
428+
metavar: str | tuple[str, ...] | None = None,
429429
) -> None: ...
430430

431431
# undocumented

0 commit comments

Comments
 (0)
0