Skip to content

Commit

Permalink
Sync typeshed (#11123)
Browse files Browse the repository at this point in the history
Source commit:
python/typeshed@e4c2c0f

Co-authored-by: hauntsaninja <>
  • Loading branch information
hauntsaninja authored Sep 17, 2021
1 parent 5bfdce8 commit 99fae38
Show file tree
Hide file tree
Showing 29 changed files with 609 additions and 307 deletions.
12 changes: 8 additions & 4 deletions mypy/typeshed/stdlib/@python2/hashlib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ from typing import Tuple, Union
_DataType = Union[str, unicode, bytearray, buffer, memoryview]

class _hash(object): # This is not actually in the module namespace.
name: str
block_size: int
digest_size: int
digestsize: int
@property
def name(self) -> str: ...
@property
def block_size(self) -> int: ...
@property
def digest_size(self) -> int: ...
@property
def digestsize(self) -> int: ...
def __init__(self, arg: _DataType = ...) -> None: ...
def update(self, arg: _DataType) -> None: ...
def digest(self) -> str: ...
Expand Down
1 change: 1 addition & 0 deletions mypy/typeshed/stdlib/@python2/logging/handlers.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class SysLogHandler(Handler):
LOG_LOCAL5: int
LOG_LOCAL6: int
LOG_LOCAL7: int
address: Tuple[str, int] | str # undocumented
unixsocket: bool # undocumented
socktype: SocketKind # undocumented
facility: int # undocumented
Expand Down
2 changes: 1 addition & 1 deletion mypy/typeshed/stdlib/VERSIONS
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ audioop: 2.7-
base64: 2.7-
bdb: 2.7-
binascii: 2.7-
binhex: 2.7-
binhex: 2.7-3.10
bisect: 2.7-
builtins: 3.0-
bz2: 2.7-
Expand Down
13 changes: 12 additions & 1 deletion mypy/typeshed/stdlib/_typeshed/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import array
import mmap
import sys
from os import PathLike
from typing import AbstractSet, Any, Container, Iterable, Protocol, Tuple, TypeVar, Union
from typing import AbstractSet, Any, Awaitable, Container, Iterable, Protocol, Tuple, TypeVar, Union
from typing_extensions import Literal, final

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

# stable
class SupportsNext(Protocol[_T_co]):
def __next__(self) -> _T_co: ...

# stable
class SupportsAnext(Protocol[_T_co]):
def __anext__(self) -> Awaitable[_T_co]: ...

class SupportsLessThan(Protocol):
def __lt__(self, __other: Any) -> bool: ...

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

class SupportsTrunc(Protocol):
def __trunc__(self) -> int: ...

# Mapping-like protocols

# stable
Expand Down
2 changes: 1 addition & 1 deletion mypy/typeshed/stdlib/asyncio/futures.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Future(Awaitable[_T], Iterable[_T]):
def _callbacks(self: _S) -> list[Callable[[_S], Any]]: ...
def add_done_callback(self: _S, __fn: Callable[[_S], Any]) -> None: ...
if sys.version_info >= (3, 9):
def cancel(self, msg: str | None = ...) -> bool: ...
def cancel(self, msg: Any | None = ...) -> bool: ...
else:
def cancel(self) -> bool: ...
def cancelled(self) -> bool: ...
Expand Down
2 changes: 1 addition & 1 deletion mypy/typeshed/stdlib/asyncio/protocols.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ if sys.version_info >= (3, 7):
def buffer_updated(self, nbytes: int) -> None: ...

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

Expand Down
2 changes: 1 addition & 1 deletion mypy/typeshed/stdlib/asyncio/tasks.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ class Task(Future[_T], Generic[_T]):
def get_stack(self, *, limit: int | None = ...) -> list[FrameType]: ...
def print_stack(self, *, limit: int | None = ..., file: TextIO | None = ...) -> None: ...
if sys.version_info >= (3, 9):
def cancel(self, msg: str | None = ...) -> bool: ...
def cancel(self, msg: Any | None = ...) -> bool: ...
else:
def cancel(self) -> bool: ...
if sys.version_info < (3, 9):
Expand Down
10 changes: 6 additions & 4 deletions mypy/typeshed/stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ from _typeshed import (
ReadableBuffer,
Self,
StrOrBytesPath,
SupportsAnext,
SupportsDivMod,
SupportsKeysAndGetItem,
SupportsLenAndGetItem,
SupportsLessThan,
SupportsLessThanT,
SupportsNext,
SupportsRDivMod,
SupportsWrite,
)
Expand Down Expand Up @@ -967,9 +969,9 @@ class _PathLike(Protocol[_AnyStr_co]):
if sys.version_info >= (3, 10):
def aiter(__iterable: AsyncIterable[_T]) -> AsyncIterator[_T]: ...
@overload
async def anext(__i: AsyncIterator[_T]) -> _T: ...
async def anext(__i: SupportsAnext[_T]) -> _T: ...
@overload
async def anext(__i: AsyncIterator[_T], default: _VT) -> _T | _VT: ...
async def anext(__i: SupportsAnext[_T], default: _VT) -> _T | _VT: ...

if sys.version_info >= (3, 8):
def compile(
Expand Down Expand Up @@ -1131,9 +1133,9 @@ def min(__iterable: Iterable[SupportsLessThanT], *, key: None = ..., default: _T
@overload
def min(__iterable: Iterable[_T1], *, key: Callable[[_T1], SupportsLessThan], default: _T2) -> _T1 | _T2: ...
@overload
def next(__i: Iterator[_T]) -> _T: ...
def next(__i: SupportsNext[_T]) -> _T: ...
@overload
def next(__i: Iterator[_T], default: _VT) -> _T | _VT: ...
def next(__i: SupportsNext[_T], default: _VT) -> _T | _VT: ...
def oct(__number: int | SupportsIndex) -> str: ...

_OpenFile = Union[StrOrBytesPath, int]
Expand Down
13 changes: 8 additions & 5 deletions mypy/typeshed/stdlib/concurrent/futures/_base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import sys
import threading
from _typeshed import Self
from abc import abstractmethod
from collections.abc import Container, Iterable, Iterator, Sequence
from logging import Logger
from typing import Any, Callable, Container, Generic, Iterable, Iterator, Protocol, Sequence, Set, TypeVar, overload
from typing import Any, Callable, Generic, Protocol, Set, TypeVar, overload

if sys.version_info >= (3, 9):
from types import GenericAlias
Expand All @@ -16,6 +17,8 @@ RUNNING: str
CANCELLED: str
CANCELLED_AND_NOTIFIED: str
FINISHED: str
_FUTURE_STATES: list[str]
_STATE_TO_DESCRIPTION_MAP: dict[str, str]
LOGGER: Logger

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

# Ideally this would be a namedtuple, but mypy doesn't support generic tuple types. See #1976
class DoneAndNotDoneFutures(Sequence[Set[Future[_T]]]):
done: Set[Future[_T]]
not_done: Set[Future[_T]]
def __new__(_cls, done: Set[Future[_T]], not_done: Set[Future[_T]]) -> DoneAndNotDoneFutures[_T]: ...
done: set[Future[_T]]
not_done: set[Future[_T]]
def __new__(_cls, done: set[Future[_T]], not_done: set[Future[_T]]) -> DoneAndNotDoneFutures[_T]: ...
def __len__(self) -> int: ...
@overload
def __getitem__(self, i: int) -> Set[Future[_T]]: ...
def __getitem__(self, i: int) -> set[Future[_T]]: ...
@overload
def __getitem__(self, s: slice) -> DoneAndNotDoneFutures[_T]: ...

Expand Down
157 changes: 148 additions & 9 deletions mypy/typeshed/stdlib/concurrent/futures/process.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,133 @@
import sys
from typing import Any, Callable, Tuple
from collections.abc import Generator, Iterable, Mapping, MutableMapping, MutableSequence
from multiprocessing.connection import Connection
from multiprocessing.context import BaseContext, Process
from multiprocessing.queues import Queue, SimpleQueue
from threading import Lock, Semaphore, Thread
from types import TracebackType
from typing import Any, Callable, Generic, Tuple, TypeVar
from weakref import ref

from ._base import Executor
from ._base import Executor, Future

EXTRA_QUEUED_CALLS: Any
_threads_wakeups: MutableMapping[Any, Any]
_global_shutdown: bool

class _ThreadWakeup:
_closed: bool
_reader: Connection
_writer: Connection
def __init__(self) -> None: ...
def close(self) -> None: ...
def wakeup(self) -> None: ...
def clear(self) -> None: ...

def _python_exit() -> None: ...

EXTRA_QUEUED_CALLS: int

_MAX_WINDOWS_WORKERS: int

class _RemoteTraceback(Exception):
tb: str
def __init__(self, tb: TracebackType) -> None: ...
def __str__(self) -> str: ...

class _ExceptionWithTraceback:
exc: BaseException
tb: TracebackType
def __init__(self, exc: BaseException, tb: TracebackType) -> None: ...
def __reduce__(self) -> str | Tuple[Any, ...]: ...

def _rebuild_exc(exc: Exception, tb: str) -> Exception: ...

_S = TypeVar("_S")

class _WorkItem(Generic[_S]):
future: Future[_S]
fn: Callable[..., _S]
args: Iterable[Any]
kwargs: Mapping[str, Any]
def __init__(self, future: Future[_S], fn: Callable[..., _S], args: Iterable[Any], kwargs: Mapping[str, Any]) -> None: ...

class _ResultItem:
work_id: int
exception: Exception
result: Any
def __init__(self, work_id: int, exception: Exception | None = ..., result: Any | None = ...) -> None: ...

class _CallItem:
work_id: int
fn: Callable[..., Any]
args: Iterable[Any]
kwargs: Mapping[str, Any]
def __init__(self, work_id: int, fn: Callable[..., Any], args: Iterable[Any], kwargs: Mapping[str, Any]) -> None: ...

if sys.version_info >= (3, 7):
class _SafeQueue(Queue[Future[Any]]):
pending_work_items: dict[int, _WorkItem[Any]]
shutdown_lock: Lock
thread_wakeup: _ThreadWakeup
if sys.version_info >= (3, 9):
def __init__(
self,
max_size: int | None = ...,
*,
ctx: BaseContext,
pending_work_items: dict[int, _WorkItem[Any]],
shutdown_lock: Lock,
thread_wakeup: _ThreadWakeup,
) -> None: ...
else:
def __init__(
self, max_size: int | None = ..., *, ctx: BaseContext, pending_work_items: dict[int, _WorkItem[Any]]
) -> None: ...
def _on_queue_feeder_error(self, e: Exception, obj: _CallItem) -> None: ...

def _get_chunks(*iterables: Any, chunksize: int) -> Generator[Tuple[Any, ...], None, None]: ...
def _process_chunk(fn: Callable[..., Any], chunk: Tuple[Any, None, None]) -> Generator[Any, None, None]: ...
def _sendback_result(
result_queue: SimpleQueue[_WorkItem[Any]], work_id: int, result: Any | None = ..., exception: Exception | None = ...
) -> None: ...

if sys.version_info >= (3, 7):
def _process_worker(
call_queue: Queue[_CallItem],
result_queue: SimpleQueue[_ResultItem],
initializer: Callable[..., None] | None,
initargs: Tuple[Any, ...],
) -> None: ...

else:
def _process_worker(call_queue: Queue[_CallItem], result_queue: SimpleQueue[_ResultItem]) -> None: ...

if sys.version_info >= (3, 9):
class _ExecutorManagerThread(Thread):
thread_wakeup: _ThreadWakeup
shutdown_lock: Lock
executor_reference: ref[Any]
processes: MutableMapping[int, Process]
call_queue: Queue[_CallItem]
result_queue: SimpleQueue[_ResultItem]
work_ids_queue: Queue[int]
pending_work_items: dict[int, _WorkItem[Any]]
def __init__(self, executor: ProcessPoolExecutor) -> None: ...
def run(self) -> None: ...
def add_call_item_to_queue(self) -> None: ...
def wait_result_broken_or_wakeup(self) -> tuple[Any, bool, str]: ...
def process_result_item(self, result_item: int | _ResultItem) -> None: ...
def is_shutting_down(self) -> bool: ...
def terminate_broken(self, cause: str) -> None: ...
def flag_executor_shutting_down(self) -> None: ...
def shutdown_workers(self) -> None: ...
def join_executor_internals(self) -> None: ...
def get_n_children_alive(self) -> int: ...

_system_limits_checked: bool
_system_limited: bool | None

def _check_system_limits() -> None: ...
def _chain_from_iterable_of_lists(iterable: Iterable[MutableSequence[Any]]) -> Any: ...

if sys.version_info >= (3, 7):
from ._base import BrokenExecutor
Expand All @@ -12,17 +136,32 @@ if sys.version_info >= (3, 7):
else:
class BrokenProcessPool(RuntimeError): ...

if sys.version_info >= (3, 7):
from multiprocessing.context import BaseContext
class ProcessPoolExecutor(Executor):
class ProcessPoolExecutor(Executor):
_mp_context: BaseContext | None = ...
_initializer: Callable[..., None] | None = ...
_initargs: Tuple[Any, ...] = ...
_executor_manager_thread: _ThreadWakeup
_processes: MutableMapping[int, Process]
_shutdown_thread: bool
_shutdown_lock: Lock
_idle_worker_semaphore: Semaphore
_broken: bool
_queue_count: int
_pending_work_items: dict[int, _WorkItem[Any]]
_cancel_pending_futures: bool
_executor_manager_thread_wakeup: _ThreadWakeup
_result_queue: SimpleQueue[Any]
_work_ids: Queue[Any]
if sys.version_info >= (3, 7):
def __init__(
self,
max_workers: int | None = ...,
mp_context: BaseContext | None = ...,
initializer: Callable[..., None] | None = ...,
initargs: Tuple[Any, ...] = ...,
) -> None: ...

else:
class ProcessPoolExecutor(Executor):
else:
def __init__(self, max_workers: int | None = ...) -> None: ...
if sys.version_info >= (3, 9):
def _start_executor_manager_thread(self) -> None: ...
def _adjust_process_count(self) -> None: ...
Loading

0 comments on commit 99fae38

Please sign in to comment.