Skip to content

Commit b08c8b5

Browse files
github-actions[bot]hauntsaninjaAlexWaygood
authored
Sync typeshed (#16721)
Source commit: python/typeshed@1d3c326 Co-authored-by: mypybot <> Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Co-authored-by: AlexWaygood <alex.waygood@gmail.com>
1 parent 761965d commit b08c8b5

File tree

15 files changed

+470
-279
lines changed

15 files changed

+470
-279
lines changed

mypy/typeshed/stdlib/VERSIONS

Lines changed: 223 additions & 222 deletions
Large diffs are not rendered by default.

mypy/typeshed/stdlib/_ast.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,9 @@ if sys.version_info >= (3, 10):
586586
patterns: list[pattern]
587587

588588
if sys.version_info >= (3, 12):
589-
class type_param(AST): ...
589+
class type_param(AST):
590+
end_lineno: int
591+
end_col_offset: int
590592

591593
class TypeVar(type_param):
592594
__match_args__ = ("name", "bound")

mypy/typeshed/stdlib/_thread.pyi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,8 @@ if sys.version_info >= (3, 8):
4646

4747
if sys.version_info >= (3, 12):
4848
def daemon_threads_allowed() -> bool: ...
49+
50+
class _local:
51+
def __getattribute__(self, __name: str) -> Any: ...
52+
def __setattr__(self, __name: str, __value: Any) -> None: ...
53+
def __delattr__(self, __name: str) -> None: ...

mypy/typeshed/stdlib/asyncore.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ if sys.platform != "win32":
8383
def write(self, data: bytes, flags: int = ...) -> int: ...
8484
def close(self) -> None: ...
8585
def fileno(self) -> int: ...
86+
def __del__(self) -> None: ...
8687

8788
class file_dispatcher(dispatcher):
8889
def __init__(self, fd: FileDescriptorLike, map: _MapType | None = None) -> None: ...

mypy/typeshed/stdlib/base64.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ if sys.version_info >= (3, 10):
2727
__all__ += ["b32hexencode", "b32hexdecode"]
2828

2929
def b64encode(s: ReadableBuffer, altchars: ReadableBuffer | None = None) -> bytes: ...
30-
def b64decode(s: str | ReadableBuffer, altchars: ReadableBuffer | None = None, validate: bool = False) -> bytes: ...
30+
def b64decode(s: str | ReadableBuffer, altchars: str | ReadableBuffer | None = None, validate: bool = False) -> bytes: ...
3131
def standard_b64encode(s: ReadableBuffer) -> bytes: ...
3232
def standard_b64decode(s: str | ReadableBuffer) -> bytes: ...
3333
def urlsafe_b64encode(s: ReadableBuffer) -> bytes: ...
3434
def urlsafe_b64decode(s: str | ReadableBuffer) -> bytes: ...
3535
def b32encode(s: ReadableBuffer) -> bytes: ...
36-
def b32decode(s: str | ReadableBuffer, casefold: bool = False, map01: bytes | None = None) -> bytes: ...
36+
def b32decode(s: str | ReadableBuffer, casefold: bool = False, map01: str | ReadableBuffer | None = None) -> bytes: ...
3737
def b16encode(s: ReadableBuffer) -> bytes: ...
3838
def b16decode(s: str | ReadableBuffer, casefold: bool = False) -> bytes: ...
3939

mypy/typeshed/stdlib/concurrent/futures/process.pyi

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ from multiprocessing.context import BaseContext, Process
55
from multiprocessing.queues import Queue, SimpleQueue
66
from threading import Lock, Semaphore, Thread
77
from types import TracebackType
8-
from typing import Any, Generic, TypeVar
8+
from typing import Any, Generic, TypeVar, overload
9+
from typing_extensions import TypeVarTuple, Unpack
910
from weakref import ref
1011

1112
from ._base import BrokenExecutor, Executor, Future
1213

1314
_T = TypeVar("_T")
15+
_Ts = TypeVarTuple("_Ts")
1416

1517
_threads_wakeups: MutableMapping[Any, Any]
1618
_global_shutdown: bool
@@ -109,17 +111,17 @@ if sys.version_info >= (3, 11):
109111
def _process_worker(
110112
call_queue: Queue[_CallItem],
111113
result_queue: SimpleQueue[_ResultItem],
112-
initializer: Callable[..., object] | None,
113-
initargs: tuple[Any, ...],
114+
initializer: Callable[[Unpack[_Ts]], object] | None,
115+
initargs: tuple[Unpack[_Ts]],
114116
max_tasks: int | None = None,
115117
) -> None: ...
116118

117119
else:
118120
def _process_worker(
119121
call_queue: Queue[_CallItem],
120122
result_queue: SimpleQueue[_ResultItem],
121-
initializer: Callable[..., object] | None,
122-
initargs: tuple[Any, ...],
123+
initializer: Callable[[Unpack[_Ts]], object] | None,
124+
initargs: tuple[Unpack[_Ts]],
123125
) -> None: ...
124126

125127
if sys.version_info >= (3, 9):
@@ -169,22 +171,61 @@ class ProcessPoolExecutor(Executor):
169171
_result_queue: SimpleQueue[Any]
170172
_work_ids: Queue[Any]
171173
if sys.version_info >= (3, 11):
174+
@overload
172175
def __init__(
173176
self,
174177
max_workers: int | None = None,
175178
mp_context: BaseContext | None = None,
176-
initializer: Callable[..., object] | None = None,
177-
initargs: tuple[Any, ...] = (),
179+
initializer: Callable[[], object] | None = None,
180+
initargs: tuple[()] = (),
181+
*,
182+
max_tasks_per_child: int | None = None,
183+
) -> None: ...
184+
@overload
185+
def __init__(
186+
self,
187+
max_workers: int | None = None,
188+
mp_context: BaseContext | None = None,
189+
*,
190+
initializer: Callable[[Unpack[_Ts]], object],
191+
initargs: tuple[Unpack[_Ts]],
192+
max_tasks_per_child: int | None = None,
193+
) -> None: ...
194+
@overload
195+
def __init__(
196+
self,
197+
max_workers: int | None,
198+
mp_context: BaseContext | None,
199+
initializer: Callable[[Unpack[_Ts]], object],
200+
initargs: tuple[Unpack[_Ts]],
178201
*,
179202
max_tasks_per_child: int | None = None,
180203
) -> None: ...
181204
else:
205+
@overload
206+
def __init__(
207+
self,
208+
max_workers: int | None = None,
209+
mp_context: BaseContext | None = None,
210+
initializer: Callable[[], object] | None = None,
211+
initargs: tuple[()] = (),
212+
) -> None: ...
213+
@overload
182214
def __init__(
183215
self,
184216
max_workers: int | None = None,
185217
mp_context: BaseContext | None = None,
186-
initializer: Callable[..., object] | None = None,
187-
initargs: tuple[Any, ...] = (),
218+
*,
219+
initializer: Callable[[Unpack[_Ts]], object],
220+
initargs: tuple[Unpack[_Ts]],
221+
) -> None: ...
222+
@overload
223+
def __init__(
224+
self,
225+
max_workers: int | None,
226+
mp_context: BaseContext | None,
227+
initializer: Callable[[Unpack[_Ts]], object],
228+
initargs: tuple[Unpack[_Ts]],
188229
) -> None: ...
189230
if sys.version_info >= (3, 9):
190231
def _start_executor_manager_thread(self) -> None: ...

mypy/typeshed/stdlib/concurrent/futures/thread.pyi

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ import queue
22
import sys
33
from collections.abc import Callable, Iterable, Mapping, Set as AbstractSet
44
from threading import Lock, Semaphore, Thread
5-
from typing import Any, Generic, TypeVar
5+
from typing import Any, Generic, TypeVar, overload
6+
from typing_extensions import TypeVarTuple, Unpack
67
from weakref import ref
78

89
from ._base import BrokenExecutor, Executor, Future
910

11+
_Ts = TypeVarTuple("_Ts")
12+
1013
_threads_queues: Mapping[Any, Any]
1114
_shutdown: bool
1215
_global_shutdown_lock: Lock
@@ -31,8 +34,8 @@ class _WorkItem(Generic[_S]):
3134
def _worker(
3235
executor_reference: ref[Any],
3336
work_queue: queue.SimpleQueue[Any],
34-
initializer: Callable[..., object],
35-
initargs: tuple[Any, ...],
37+
initializer: Callable[[Unpack[_Ts]], object],
38+
initargs: tuple[Unpack[_Ts]],
3639
) -> None: ...
3740

3841
class BrokenThreadPool(BrokenExecutor): ...
@@ -48,12 +51,30 @@ class ThreadPoolExecutor(Executor):
4851
_initializer: Callable[..., None] | None
4952
_initargs: tuple[Any, ...]
5053
_work_queue: queue.SimpleQueue[_WorkItem[Any]]
54+
@overload
5155
def __init__(
5256
self,
5357
max_workers: int | None = None,
5458
thread_name_prefix: str = "",
55-
initializer: Callable[..., object] | None = None,
56-
initargs: tuple[Any, ...] = (),
59+
initializer: Callable[[], object] | None = None,
60+
initargs: tuple[()] = (),
61+
) -> None: ...
62+
@overload
63+
def __init__(
64+
self,
65+
max_workers: int | None = None,
66+
thread_name_prefix: str = "",
67+
*,
68+
initializer: Callable[[Unpack[_Ts]], object],
69+
initargs: tuple[Unpack[_Ts]],
70+
) -> None: ...
71+
@overload
72+
def __init__(
73+
self,
74+
max_workers: int | None,
75+
thread_name_prefix: str,
76+
initializer: Callable[[Unpack[_Ts]], object],
77+
initargs: tuple[Unpack[_Ts]],
5778
) -> None: ...
5879
def _adjust_thread_count(self) -> None: ...
5980
def _initializer_failed(self) -> None: ...

mypy/typeshed/stdlib/http/client.pyi

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,24 @@ responses: dict[int, str]
9999

100100
class HTTPMessage(email.message.Message):
101101
def getallmatchingheaders(self, name: str) -> list[str]: ... # undocumented
102+
# override below all of Message's methods that use `_HeaderType` / `_HeaderTypeParam` with `str`
103+
# `HTTPMessage` breaks the Liskov substitution principle by only intending for `str` headers
104+
# This is easier than making `Message` generic
105+
def __getitem__(self, name: str) -> str | None: ...
106+
def __setitem__(self, name: str, val: str) -> None: ... # type: ignore[override]
107+
def values(self) -> list[str]: ...
108+
def items(self) -> list[tuple[str, str]]: ...
109+
@overload
110+
def get(self, name: str, failobj: None = None) -> str | None: ...
111+
@overload
112+
def get(self, name: str, failobj: _T) -> str | _T: ...
113+
@overload
114+
def get_all(self, name: str, failobj: None = None) -> list[str] | None: ...
115+
@overload
116+
def get_all(self, name: str, failobj: _T) -> list[str] | _T: ...
117+
def replace_header(self, _name: str, _value: str) -> None: ... # type: ignore[override]
118+
def set_raw(self, name: str, value: str) -> None: ... # type: ignore[override]
119+
def raw_items(self) -> Iterator[tuple[str, str]]: ...
102120

103121
def parse_headers(fp: io.BufferedIOBase, _class: Callable[[], email.message.Message] = ...) -> HTTPMessage: ...
104122

mypy/typeshed/stdlib/os/__init__.pyi

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ from . import path as _path
3333
if sys.version_info >= (3, 9):
3434
from types import GenericAlias
3535

36+
if sys.platform != "win32":
37+
from resource import struct_rusage
38+
3639
# This unnecessary alias is to work around various errors
3740
path = _path
3841

@@ -962,8 +965,8 @@ else:
962965

963966
def waitid(__idtype: int, __ident: int, __options: int) -> waitid_result | None: ...
964967

965-
def wait3(options: int) -> tuple[int, int, Any]: ...
966-
def wait4(pid: int, options: int) -> tuple[int, int, Any]: ...
968+
def wait3(options: int) -> tuple[int, int, struct_rusage]: ...
969+
def wait4(pid: int, options: int) -> tuple[int, int, struct_rusage]: ...
967970
def WCOREDUMP(__status: int) -> bool: ...
968971
def WIFCONTINUED(status: int) -> bool: ...
969972
def WIFSTOPPED(status: int) -> bool: ...

mypy/typeshed/stdlib/selectors.pyi

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,49 +31,37 @@ class BaseSelector(metaclass=ABCMeta):
3131
def __enter__(self) -> Self: ...
3232
def __exit__(self, *args: Unused) -> None: ...
3333

34-
class SelectSelector(BaseSelector):
34+
class _BaseSelectorImpl(BaseSelector, metaclass=ABCMeta):
3535
def register(self, fileobj: FileDescriptorLike, events: _EventMask, data: Any = None) -> SelectorKey: ...
3636
def unregister(self, fileobj: FileDescriptorLike) -> SelectorKey: ...
37-
def select(self, timeout: float | None = None) -> list[tuple[SelectorKey, _EventMask]]: ...
37+
def modify(self, fileobj: FileDescriptorLike, events: _EventMask, data: Any = None) -> SelectorKey: ...
3838
def get_map(self) -> Mapping[FileDescriptorLike, SelectorKey]: ...
3939

40+
class SelectSelector(_BaseSelectorImpl):
41+
def select(self, timeout: float | None = None) -> list[tuple[SelectorKey, _EventMask]]: ...
42+
43+
class _PollLikeSelector(_BaseSelectorImpl):
44+
def select(self, timeout: float | None = None) -> list[tuple[SelectorKey, _EventMask]]: ...
45+
4046
if sys.platform != "win32":
41-
class PollSelector(BaseSelector):
42-
def register(self, fileobj: FileDescriptorLike, events: _EventMask, data: Any = None) -> SelectorKey: ...
43-
def unregister(self, fileobj: FileDescriptorLike) -> SelectorKey: ...
44-
def select(self, timeout: float | None = None) -> list[tuple[SelectorKey, _EventMask]]: ...
45-
def get_map(self) -> Mapping[FileDescriptorLike, SelectorKey]: ...
47+
class PollSelector(_PollLikeSelector): ...
4648

4749
if sys.platform == "linux":
48-
class EpollSelector(BaseSelector):
50+
class EpollSelector(_PollLikeSelector):
4951
def fileno(self) -> int: ...
50-
def register(self, fileobj: FileDescriptorLike, events: _EventMask, data: Any = None) -> SelectorKey: ...
51-
def unregister(self, fileobj: FileDescriptorLike) -> SelectorKey: ...
52-
def select(self, timeout: float | None = None) -> list[tuple[SelectorKey, _EventMask]]: ...
53-
def get_map(self) -> Mapping[FileDescriptorLike, SelectorKey]: ...
5452

55-
class DevpollSelector(BaseSelector):
53+
class DevpollSelector(_PollLikeSelector):
5654
def fileno(self) -> int: ...
57-
def register(self, fileobj: FileDescriptorLike, events: _EventMask, data: Any = ...) -> SelectorKey: ...
58-
def unregister(self, fileobj: FileDescriptorLike) -> SelectorKey: ...
59-
def select(self, timeout: float | None = ...) -> list[tuple[SelectorKey, _EventMask]]: ...
60-
def get_map(self) -> Mapping[FileDescriptorLike, SelectorKey]: ...
6155

6256
if sys.platform != "win32":
63-
class KqueueSelector(BaseSelector):
57+
class KqueueSelector(_BaseSelectorImpl):
6458
def fileno(self) -> int: ...
65-
def register(self, fileobj: FileDescriptorLike, events: _EventMask, data: Any = None) -> SelectorKey: ...
66-
def unregister(self, fileobj: FileDescriptorLike) -> SelectorKey: ...
6759
def select(self, timeout: float | None = None) -> list[tuple[SelectorKey, _EventMask]]: ...
68-
def get_map(self) -> Mapping[FileDescriptorLike, SelectorKey]: ...
6960

7061
# Not a real class at runtime, it is just a conditional alias to other real selectors.
7162
# The runtime logic is more fine-grained than a `sys.platform` check;
7263
# not really expressible in the stubs
73-
class DefaultSelector(BaseSelector):
74-
def register(self, fileobj: FileDescriptorLike, events: _EventMask, data: Any = None) -> SelectorKey: ...
75-
def unregister(self, fileobj: FileDescriptorLike) -> SelectorKey: ...
64+
class DefaultSelector(_BaseSelectorImpl):
7665
def select(self, timeout: float | None = None) -> list[tuple[SelectorKey, _EventMask]]: ...
77-
def get_map(self) -> Mapping[FileDescriptorLike, SelectorKey]: ...
7866
if sys.platform != "win32":
7967
def fileno(self) -> int: ...

0 commit comments

Comments
 (0)