Skip to content

Commit 99fae38

Browse files
authored
Sync typeshed (#11123)
Source commit: python/typeshed@e4c2c0f Co-authored-by: hauntsaninja <>
1 parent 5bfdce8 commit 99fae38

29 files changed

+609
-307
lines changed

mypy/typeshed/stdlib/@python2/hashlib.pyi

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ from typing import Tuple, Union
33
_DataType = Union[str, unicode, bytearray, buffer, memoryview]
44

55
class _hash(object): # This is not actually in the module namespace.
6-
name: str
7-
block_size: int
8-
digest_size: int
9-
digestsize: int
6+
@property
7+
def name(self) -> str: ...
8+
@property
9+
def block_size(self) -> int: ...
10+
@property
11+
def digest_size(self) -> int: ...
12+
@property
13+
def digestsize(self) -> int: ...
1014
def __init__(self, arg: _DataType = ...) -> None: ...
1115
def update(self, arg: _DataType) -> None: ...
1216
def digest(self) -> str: ...

mypy/typeshed/stdlib/@python2/logging/handlers.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class SysLogHandler(Handler):
8484
LOG_LOCAL5: int
8585
LOG_LOCAL6: int
8686
LOG_LOCAL7: int
87+
address: Tuple[str, int] | str # undocumented
8788
unixsocket: bool # undocumented
8889
socktype: SocketKind # undocumented
8990
facility: int # undocumented

mypy/typeshed/stdlib/VERSIONS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ audioop: 2.7-
6868
base64: 2.7-
6969
bdb: 2.7-
7070
binascii: 2.7-
71-
binhex: 2.7-
71+
binhex: 2.7-3.10
7272
bisect: 2.7-
7373
builtins: 3.0-
7474
bz2: 2.7-

mypy/typeshed/stdlib/_typeshed/__init__.pyi

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import array
66
import mmap
77
import sys
88
from os import PathLike
9-
from typing import AbstractSet, Any, Container, Iterable, Protocol, Tuple, TypeVar, Union
9+
from typing import AbstractSet, Any, Awaitable, Container, Iterable, Protocol, Tuple, TypeVar, Union
1010
from typing_extensions import Literal, final
1111

1212
_KT = TypeVar("_KT")
@@ -26,6 +26,14 @@ Self = TypeVar("Self") # noqa Y001
2626
class IdentityFunction(Protocol):
2727
def __call__(self, __x: _T) -> _T: ...
2828

29+
# stable
30+
class SupportsNext(Protocol[_T_co]):
31+
def __next__(self) -> _T_co: ...
32+
33+
# stable
34+
class SupportsAnext(Protocol[_T_co]):
35+
def __anext__(self) -> Awaitable[_T_co]: ...
36+
2937
class SupportsLessThan(Protocol):
3038
def __lt__(self, __other: Any) -> bool: ...
3139

@@ -41,6 +49,9 @@ class SupportsLenAndGetItem(Protocol[_T_co]):
4149
def __len__(self) -> int: ...
4250
def __getitem__(self, __k: int) -> _T_co: ...
4351

52+
class SupportsTrunc(Protocol):
53+
def __trunc__(self) -> int: ...
54+
4455
# Mapping-like protocols
4556

4657
# stable

mypy/typeshed/stdlib/asyncio/futures.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Future(Awaitable[_T], Iterable[_T]):
4545
def _callbacks(self: _S) -> list[Callable[[_S], Any]]: ...
4646
def add_done_callback(self: _S, __fn: Callable[[_S], Any]) -> None: ...
4747
if sys.version_info >= (3, 9):
48-
def cancel(self, msg: str | None = ...) -> bool: ...
48+
def cancel(self, msg: Any | None = ...) -> bool: ...
4949
else:
5050
def cancel(self) -> bool: ...
5151
def cancelled(self) -> bool: ...

mypy/typeshed/stdlib/asyncio/protocols.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if sys.version_info >= (3, 7):
1818
def buffer_updated(self, nbytes: int) -> None: ...
1919

2020
class DatagramProtocol(BaseProtocol):
21-
def connection_made(self, transport: transports.DatagramTransport) -> None: ... # type: ignore[override]
21+
def connection_made(self, transport: transports.DatagramTransport) -> None: ... # type: ignore
2222
def datagram_received(self, data: bytes, addr: Tuple[str, int]) -> None: ...
2323
def error_received(self, exc: Exception) -> None: ...
2424

mypy/typeshed/stdlib/asyncio/tasks.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ class Task(Future[_T], Generic[_T]):
271271
def get_stack(self, *, limit: int | None = ...) -> list[FrameType]: ...
272272
def print_stack(self, *, limit: int | None = ..., file: TextIO | None = ...) -> None: ...
273273
if sys.version_info >= (3, 9):
274-
def cancel(self, msg: str | None = ...) -> bool: ...
274+
def cancel(self, msg: Any | None = ...) -> bool: ...
275275
else:
276276
def cancel(self) -> bool: ...
277277
if sys.version_info < (3, 9):

mypy/typeshed/stdlib/builtins.pyi

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ from _typeshed import (
99
ReadableBuffer,
1010
Self,
1111
StrOrBytesPath,
12+
SupportsAnext,
1213
SupportsDivMod,
1314
SupportsKeysAndGetItem,
1415
SupportsLenAndGetItem,
1516
SupportsLessThan,
1617
SupportsLessThanT,
18+
SupportsNext,
1719
SupportsRDivMod,
1820
SupportsWrite,
1921
)
@@ -967,9 +969,9 @@ class _PathLike(Protocol[_AnyStr_co]):
967969
if sys.version_info >= (3, 10):
968970
def aiter(__iterable: AsyncIterable[_T]) -> AsyncIterator[_T]: ...
969971
@overload
970-
async def anext(__i: AsyncIterator[_T]) -> _T: ...
972+
async def anext(__i: SupportsAnext[_T]) -> _T: ...
971973
@overload
972-
async def anext(__i: AsyncIterator[_T], default: _VT) -> _T | _VT: ...
974+
async def anext(__i: SupportsAnext[_T], default: _VT) -> _T | _VT: ...
973975

974976
if sys.version_info >= (3, 8):
975977
def compile(
@@ -1131,9 +1133,9 @@ def min(__iterable: Iterable[SupportsLessThanT], *, key: None = ..., default: _T
11311133
@overload
11321134
def min(__iterable: Iterable[_T1], *, key: Callable[[_T1], SupportsLessThan], default: _T2) -> _T1 | _T2: ...
11331135
@overload
1134-
def next(__i: Iterator[_T]) -> _T: ...
1136+
def next(__i: SupportsNext[_T]) -> _T: ...
11351137
@overload
1136-
def next(__i: Iterator[_T], default: _VT) -> _T | _VT: ...
1138+
def next(__i: SupportsNext[_T], default: _VT) -> _T | _VT: ...
11371139
def oct(__number: int | SupportsIndex) -> str: ...
11381140

11391141
_OpenFile = Union[StrOrBytesPath, int]

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import sys
22
import threading
33
from _typeshed import Self
44
from abc import abstractmethod
5+
from collections.abc import Container, Iterable, Iterator, Sequence
56
from logging import Logger
6-
from typing import Any, Callable, Container, Generic, Iterable, Iterator, Protocol, Sequence, Set, TypeVar, overload
7+
from typing import Any, Callable, Generic, Protocol, Set, TypeVar, overload
78

89
if sys.version_info >= (3, 9):
910
from types import GenericAlias
@@ -16,6 +17,8 @@ RUNNING: str
1617
CANCELLED: str
1718
CANCELLED_AND_NOTIFIED: str
1819
FINISHED: str
20+
_FUTURE_STATES: list[str]
21+
_STATE_TO_DESCRIPTION_MAP: dict[str, str]
1922
LOGGER: Logger
2023

2124
class Error(Exception): ...
@@ -73,12 +76,12 @@ def as_completed(fs: Iterable[Future[_T]], timeout: float | None = ...) -> Itera
7376

7477
# Ideally this would be a namedtuple, but mypy doesn't support generic tuple types. See #1976
7578
class DoneAndNotDoneFutures(Sequence[Set[Future[_T]]]):
76-
done: Set[Future[_T]]
77-
not_done: Set[Future[_T]]
78-
def __new__(_cls, done: Set[Future[_T]], not_done: Set[Future[_T]]) -> DoneAndNotDoneFutures[_T]: ...
79+
done: set[Future[_T]]
80+
not_done: set[Future[_T]]
81+
def __new__(_cls, done: set[Future[_T]], not_done: set[Future[_T]]) -> DoneAndNotDoneFutures[_T]: ...
7982
def __len__(self) -> int: ...
8083
@overload
81-
def __getitem__(self, i: int) -> Set[Future[_T]]: ...
84+
def __getitem__(self, i: int) -> set[Future[_T]]: ...
8285
@overload
8386
def __getitem__(self, s: slice) -> DoneAndNotDoneFutures[_T]: ...
8487

Lines changed: 148 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,133 @@
11
import sys
2-
from typing import Any, Callable, Tuple
2+
from collections.abc import Generator, Iterable, Mapping, MutableMapping, MutableSequence
3+
from multiprocessing.connection import Connection
4+
from multiprocessing.context import BaseContext, Process
5+
from multiprocessing.queues import Queue, SimpleQueue
6+
from threading import Lock, Semaphore, Thread
7+
from types import TracebackType
8+
from typing import Any, Callable, Generic, Tuple, TypeVar
9+
from weakref import ref
310

4-
from ._base import Executor
11+
from ._base import Executor, Future
512

6-
EXTRA_QUEUED_CALLS: Any
13+
_threads_wakeups: MutableMapping[Any, Any]
14+
_global_shutdown: bool
15+
16+
class _ThreadWakeup:
17+
_closed: bool
18+
_reader: Connection
19+
_writer: Connection
20+
def __init__(self) -> None: ...
21+
def close(self) -> None: ...
22+
def wakeup(self) -> None: ...
23+
def clear(self) -> None: ...
24+
25+
def _python_exit() -> None: ...
26+
27+
EXTRA_QUEUED_CALLS: int
28+
29+
_MAX_WINDOWS_WORKERS: int
30+
31+
class _RemoteTraceback(Exception):
32+
tb: str
33+
def __init__(self, tb: TracebackType) -> None: ...
34+
def __str__(self) -> str: ...
35+
36+
class _ExceptionWithTraceback:
37+
exc: BaseException
38+
tb: TracebackType
39+
def __init__(self, exc: BaseException, tb: TracebackType) -> None: ...
40+
def __reduce__(self) -> str | Tuple[Any, ...]: ...
41+
42+
def _rebuild_exc(exc: Exception, tb: str) -> Exception: ...
43+
44+
_S = TypeVar("_S")
45+
46+
class _WorkItem(Generic[_S]):
47+
future: Future[_S]
48+
fn: Callable[..., _S]
49+
args: Iterable[Any]
50+
kwargs: Mapping[str, Any]
51+
def __init__(self, future: Future[_S], fn: Callable[..., _S], args: Iterable[Any], kwargs: Mapping[str, Any]) -> None: ...
52+
53+
class _ResultItem:
54+
work_id: int
55+
exception: Exception
56+
result: Any
57+
def __init__(self, work_id: int, exception: Exception | None = ..., result: Any | None = ...) -> None: ...
58+
59+
class _CallItem:
60+
work_id: int
61+
fn: Callable[..., Any]
62+
args: Iterable[Any]
63+
kwargs: Mapping[str, Any]
64+
def __init__(self, work_id: int, fn: Callable[..., Any], args: Iterable[Any], kwargs: Mapping[str, Any]) -> None: ...
65+
66+
if sys.version_info >= (3, 7):
67+
class _SafeQueue(Queue[Future[Any]]):
68+
pending_work_items: dict[int, _WorkItem[Any]]
69+
shutdown_lock: Lock
70+
thread_wakeup: _ThreadWakeup
71+
if sys.version_info >= (3, 9):
72+
def __init__(
73+
self,
74+
max_size: int | None = ...,
75+
*,
76+
ctx: BaseContext,
77+
pending_work_items: dict[int, _WorkItem[Any]],
78+
shutdown_lock: Lock,
79+
thread_wakeup: _ThreadWakeup,
80+
) -> None: ...
81+
else:
82+
def __init__(
83+
self, max_size: int | None = ..., *, ctx: BaseContext, pending_work_items: dict[int, _WorkItem[Any]]
84+
) -> None: ...
85+
def _on_queue_feeder_error(self, e: Exception, obj: _CallItem) -> None: ...
86+
87+
def _get_chunks(*iterables: Any, chunksize: int) -> Generator[Tuple[Any, ...], None, None]: ...
88+
def _process_chunk(fn: Callable[..., Any], chunk: Tuple[Any, None, None]) -> Generator[Any, None, None]: ...
89+
def _sendback_result(
90+
result_queue: SimpleQueue[_WorkItem[Any]], work_id: int, result: Any | None = ..., exception: Exception | None = ...
91+
) -> None: ...
92+
93+
if sys.version_info >= (3, 7):
94+
def _process_worker(
95+
call_queue: Queue[_CallItem],
96+
result_queue: SimpleQueue[_ResultItem],
97+
initializer: Callable[..., None] | None,
98+
initargs: Tuple[Any, ...],
99+
) -> None: ...
100+
101+
else:
102+
def _process_worker(call_queue: Queue[_CallItem], result_queue: SimpleQueue[_ResultItem]) -> None: ...
103+
104+
if sys.version_info >= (3, 9):
105+
class _ExecutorManagerThread(Thread):
106+
thread_wakeup: _ThreadWakeup
107+
shutdown_lock: Lock
108+
executor_reference: ref[Any]
109+
processes: MutableMapping[int, Process]
110+
call_queue: Queue[_CallItem]
111+
result_queue: SimpleQueue[_ResultItem]
112+
work_ids_queue: Queue[int]
113+
pending_work_items: dict[int, _WorkItem[Any]]
114+
def __init__(self, executor: ProcessPoolExecutor) -> None: ...
115+
def run(self) -> None: ...
116+
def add_call_item_to_queue(self) -> None: ...
117+
def wait_result_broken_or_wakeup(self) -> tuple[Any, bool, str]: ...
118+
def process_result_item(self, result_item: int | _ResultItem) -> None: ...
119+
def is_shutting_down(self) -> bool: ...
120+
def terminate_broken(self, cause: str) -> None: ...
121+
def flag_executor_shutting_down(self) -> None: ...
122+
def shutdown_workers(self) -> None: ...
123+
def join_executor_internals(self) -> None: ...
124+
def get_n_children_alive(self) -> int: ...
125+
126+
_system_limits_checked: bool
127+
_system_limited: bool | None
128+
129+
def _check_system_limits() -> None: ...
130+
def _chain_from_iterable_of_lists(iterable: Iterable[MutableSequence[Any]]) -> Any: ...
7131

8132
if sys.version_info >= (3, 7):
9133
from ._base import BrokenExecutor
@@ -12,17 +136,32 @@ if sys.version_info >= (3, 7):
12136
else:
13137
class BrokenProcessPool(RuntimeError): ...
14138

15-
if sys.version_info >= (3, 7):
16-
from multiprocessing.context import BaseContext
17-
class ProcessPoolExecutor(Executor):
139+
class ProcessPoolExecutor(Executor):
140+
_mp_context: BaseContext | None = ...
141+
_initializer: Callable[..., None] | None = ...
142+
_initargs: Tuple[Any, ...] = ...
143+
_executor_manager_thread: _ThreadWakeup
144+
_processes: MutableMapping[int, Process]
145+
_shutdown_thread: bool
146+
_shutdown_lock: Lock
147+
_idle_worker_semaphore: Semaphore
148+
_broken: bool
149+
_queue_count: int
150+
_pending_work_items: dict[int, _WorkItem[Any]]
151+
_cancel_pending_futures: bool
152+
_executor_manager_thread_wakeup: _ThreadWakeup
153+
_result_queue: SimpleQueue[Any]
154+
_work_ids: Queue[Any]
155+
if sys.version_info >= (3, 7):
18156
def __init__(
19157
self,
20158
max_workers: int | None = ...,
21159
mp_context: BaseContext | None = ...,
22160
initializer: Callable[..., None] | None = ...,
23161
initargs: Tuple[Any, ...] = ...,
24162
) -> None: ...
25-
26-
else:
27-
class ProcessPoolExecutor(Executor):
163+
else:
28164
def __init__(self, max_workers: int | None = ...) -> None: ...
165+
if sys.version_info >= (3, 9):
166+
def _start_executor_manager_thread(self) -> None: ...
167+
def _adjust_process_count(self) -> None: ...

0 commit comments

Comments
 (0)