Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
445 changes: 223 additions & 222 deletions mypy/typeshed/stdlib/VERSIONS

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion mypy/typeshed/stdlib/_ast.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,9 @@ if sys.version_info >= (3, 10):
patterns: list[pattern]

if sys.version_info >= (3, 12):
class type_param(AST): ...
class type_param(AST):
end_lineno: int
end_col_offset: int

class TypeVar(type_param):
__match_args__ = ("name", "bound")
Expand Down
5 changes: 5 additions & 0 deletions mypy/typeshed/stdlib/_thread.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,8 @@ if sys.version_info >= (3, 8):

if sys.version_info >= (3, 12):
def daemon_threads_allowed() -> bool: ...

class _local:
def __getattribute__(self, __name: str) -> Any: ...
def __setattr__(self, __name: str, __value: Any) -> None: ...
def __delattr__(self, __name: str) -> None: ...
1 change: 1 addition & 0 deletions mypy/typeshed/stdlib/asyncore.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ if sys.platform != "win32":
def write(self, data: bytes, flags: int = ...) -> int: ...
def close(self) -> None: ...
def fileno(self) -> int: ...
def __del__(self) -> None: ...

class file_dispatcher(dispatcher):
def __init__(self, fd: FileDescriptorLike, map: _MapType | None = None) -> None: ...
Expand Down
4 changes: 2 additions & 2 deletions mypy/typeshed/stdlib/base64.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ if sys.version_info >= (3, 10):
__all__ += ["b32hexencode", "b32hexdecode"]

def b64encode(s: ReadableBuffer, altchars: ReadableBuffer | None = None) -> bytes: ...
def b64decode(s: str | ReadableBuffer, altchars: ReadableBuffer | None = None, validate: bool = False) -> bytes: ...
def b64decode(s: str | ReadableBuffer, altchars: str | ReadableBuffer | None = None, validate: bool = False) -> bytes: ...
def standard_b64encode(s: ReadableBuffer) -> bytes: ...
def standard_b64decode(s: str | ReadableBuffer) -> bytes: ...
def urlsafe_b64encode(s: ReadableBuffer) -> bytes: ...
def urlsafe_b64decode(s: str | ReadableBuffer) -> bytes: ...
def b32encode(s: ReadableBuffer) -> bytes: ...
def b32decode(s: str | ReadableBuffer, casefold: bool = False, map01: bytes | None = None) -> bytes: ...
def b32decode(s: str | ReadableBuffer, casefold: bool = False, map01: str | ReadableBuffer | None = None) -> bytes: ...
def b16encode(s: ReadableBuffer) -> bytes: ...
def b16decode(s: str | ReadableBuffer, casefold: bool = False) -> bytes: ...

Expand Down
59 changes: 50 additions & 9 deletions mypy/typeshed/stdlib/concurrent/futures/process.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ 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, Generic, TypeVar
from typing import Any, Generic, TypeVar, overload
from typing_extensions import TypeVarTuple, Unpack
from weakref import ref

from ._base import BrokenExecutor, Executor, Future

_T = TypeVar("_T")
_Ts = TypeVarTuple("_Ts")

_threads_wakeups: MutableMapping[Any, Any]
_global_shutdown: bool
Expand Down Expand Up @@ -109,17 +111,17 @@ if sys.version_info >= (3, 11):
def _process_worker(
call_queue: Queue[_CallItem],
result_queue: SimpleQueue[_ResultItem],
initializer: Callable[..., object] | None,
initargs: tuple[Any, ...],
initializer: Callable[[Unpack[_Ts]], object] | None,
initargs: tuple[Unpack[_Ts]],
max_tasks: int | None = None,
) -> None: ...

else:
def _process_worker(
call_queue: Queue[_CallItem],
result_queue: SimpleQueue[_ResultItem],
initializer: Callable[..., object] | None,
initargs: tuple[Any, ...],
initializer: Callable[[Unpack[_Ts]], object] | None,
initargs: tuple[Unpack[_Ts]],
) -> None: ...

if sys.version_info >= (3, 9):
Expand Down Expand Up @@ -169,22 +171,61 @@ class ProcessPoolExecutor(Executor):
_result_queue: SimpleQueue[Any]
_work_ids: Queue[Any]
if sys.version_info >= (3, 11):
@overload
def __init__(
self,
max_workers: int | None = None,
mp_context: BaseContext | None = None,
initializer: Callable[..., object] | None = None,
initargs: tuple[Any, ...] = (),
initializer: Callable[[], object] | None = None,
initargs: tuple[()] = (),
*,
max_tasks_per_child: int | None = None,
) -> None: ...
@overload
def __init__(
self,
max_workers: int | None = None,
mp_context: BaseContext | None = None,
*,
initializer: Callable[[Unpack[_Ts]], object],
initargs: tuple[Unpack[_Ts]],
max_tasks_per_child: int | None = None,
) -> None: ...
@overload
def __init__(
self,
max_workers: int | None,
mp_context: BaseContext | None,
initializer: Callable[[Unpack[_Ts]], object],
initargs: tuple[Unpack[_Ts]],
*,
max_tasks_per_child: int | None = None,
) -> None: ...
else:
@overload
def __init__(
self,
max_workers: int | None = None,
mp_context: BaseContext | None = None,
initializer: Callable[[], object] | None = None,
initargs: tuple[()] = (),
) -> None: ...
@overload
def __init__(
self,
max_workers: int | None = None,
mp_context: BaseContext | None = None,
initializer: Callable[..., object] | None = None,
initargs: tuple[Any, ...] = (),
*,
initializer: Callable[[Unpack[_Ts]], object],
initargs: tuple[Unpack[_Ts]],
) -> None: ...
@overload
def __init__(
self,
max_workers: int | None,
mp_context: BaseContext | None,
initializer: Callable[[Unpack[_Ts]], object],
initargs: tuple[Unpack[_Ts]],
) -> None: ...
if sys.version_info >= (3, 9):
def _start_executor_manager_thread(self) -> None: ...
Expand Down
31 changes: 26 additions & 5 deletions mypy/typeshed/stdlib/concurrent/futures/thread.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import queue
import sys
from collections.abc import Callable, Iterable, Mapping, Set as AbstractSet
from threading import Lock, Semaphore, Thread
from typing import Any, Generic, TypeVar
from typing import Any, Generic, TypeVar, overload
from typing_extensions import TypeVarTuple, Unpack
from weakref import ref

from ._base import BrokenExecutor, Executor, Future

_Ts = TypeVarTuple("_Ts")

_threads_queues: Mapping[Any, Any]
_shutdown: bool
_global_shutdown_lock: Lock
Expand All @@ -31,8 +34,8 @@ class _WorkItem(Generic[_S]):
def _worker(
executor_reference: ref[Any],
work_queue: queue.SimpleQueue[Any],
initializer: Callable[..., object],
initargs: tuple[Any, ...],
initializer: Callable[[Unpack[_Ts]], object],
initargs: tuple[Unpack[_Ts]],
) -> None: ...

class BrokenThreadPool(BrokenExecutor): ...
Expand All @@ -48,12 +51,30 @@ class ThreadPoolExecutor(Executor):
_initializer: Callable[..., None] | None
_initargs: tuple[Any, ...]
_work_queue: queue.SimpleQueue[_WorkItem[Any]]
@overload
def __init__(
self,
max_workers: int | None = None,
thread_name_prefix: str = "",
initializer: Callable[..., object] | None = None,
initargs: tuple[Any, ...] = (),
initializer: Callable[[], object] | None = None,
initargs: tuple[()] = (),
) -> None: ...
@overload
def __init__(
self,
max_workers: int | None = None,
thread_name_prefix: str = "",
*,
initializer: Callable[[Unpack[_Ts]], object],
initargs: tuple[Unpack[_Ts]],
) -> None: ...
@overload
def __init__(
self,
max_workers: int | None,
thread_name_prefix: str,
initializer: Callable[[Unpack[_Ts]], object],
initargs: tuple[Unpack[_Ts]],
) -> None: ...
def _adjust_thread_count(self) -> None: ...
def _initializer_failed(self) -> None: ...
18 changes: 18 additions & 0 deletions mypy/typeshed/stdlib/http/client.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,24 @@ responses: dict[int, str]

class HTTPMessage(email.message.Message):
def getallmatchingheaders(self, name: str) -> list[str]: ... # undocumented
# override below all of Message's methods that use `_HeaderType` / `_HeaderTypeParam` with `str`
# `HTTPMessage` breaks the Liskov substitution principle by only intending for `str` headers
# This is easier than making `Message` generic
def __getitem__(self, name: str) -> str | None: ...
def __setitem__(self, name: str, val: str) -> None: ... # type: ignore[override]
def values(self) -> list[str]: ...
def items(self) -> list[tuple[str, str]]: ...
@overload
def get(self, name: str, failobj: None = None) -> str | None: ...
@overload
def get(self, name: str, failobj: _T) -> str | _T: ...
@overload
def get_all(self, name: str, failobj: None = None) -> list[str] | None: ...
@overload
def get_all(self, name: str, failobj: _T) -> list[str] | _T: ...
def replace_header(self, _name: str, _value: str) -> None: ... # type: ignore[override]
def set_raw(self, name: str, value: str) -> None: ... # type: ignore[override]
def raw_items(self) -> Iterator[tuple[str, str]]: ...

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

Expand Down
7 changes: 5 additions & 2 deletions mypy/typeshed/stdlib/os/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ from . import path as _path
if sys.version_info >= (3, 9):
from types import GenericAlias

if sys.platform != "win32":
from resource import struct_rusage

# This unnecessary alias is to work around various errors
path = _path

Expand Down Expand Up @@ -962,8 +965,8 @@ else:

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

def wait3(options: int) -> tuple[int, int, Any]: ...
def wait4(pid: int, options: int) -> tuple[int, int, Any]: ...
def wait3(options: int) -> tuple[int, int, struct_rusage]: ...
def wait4(pid: int, options: int) -> tuple[int, int, struct_rusage]: ...
def WCOREDUMP(__status: int) -> bool: ...
def WIFCONTINUED(status: int) -> bool: ...
def WIFSTOPPED(status: int) -> bool: ...
Expand Down
38 changes: 13 additions & 25 deletions mypy/typeshed/stdlib/selectors.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -31,49 +31,37 @@ class BaseSelector(metaclass=ABCMeta):
def __enter__(self) -> Self: ...
def __exit__(self, *args: Unused) -> None: ...

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

class SelectSelector(_BaseSelectorImpl):
def select(self, timeout: float | None = None) -> list[tuple[SelectorKey, _EventMask]]: ...

class _PollLikeSelector(_BaseSelectorImpl):
def select(self, timeout: float | None = None) -> list[tuple[SelectorKey, _EventMask]]: ...

if sys.platform != "win32":
class PollSelector(BaseSelector):
def register(self, fileobj: FileDescriptorLike, events: _EventMask, data: Any = None) -> SelectorKey: ...
def unregister(self, fileobj: FileDescriptorLike) -> SelectorKey: ...
def select(self, timeout: float | None = None) -> list[tuple[SelectorKey, _EventMask]]: ...
def get_map(self) -> Mapping[FileDescriptorLike, SelectorKey]: ...
class PollSelector(_PollLikeSelector): ...

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

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

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

# Not a real class at runtime, it is just a conditional alias to other real selectors.
# The runtime logic is more fine-grained than a `sys.platform` check;
# not really expressible in the stubs
class DefaultSelector(BaseSelector):
def register(self, fileobj: FileDescriptorLike, events: _EventMask, data: Any = None) -> SelectorKey: ...
def unregister(self, fileobj: FileDescriptorLike) -> SelectorKey: ...
class DefaultSelector(_BaseSelectorImpl):
def select(self, timeout: float | None = None) -> list[tuple[SelectorKey, _EventMask]]: ...
def get_map(self) -> Mapping[FileDescriptorLike, SelectorKey]: ...
if sys.platform != "win32":
def fileno(self) -> int: ...
9 changes: 3 additions & 6 deletions mypy/typeshed/stdlib/threading.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _thread
import sys
from _typeshed import ProfileFunction, TraceFunction
from collections.abc import Callable, Iterable, Mapping
Expand Down Expand Up @@ -68,12 +69,8 @@ def stack_size(size: int = ...) -> int: ...

TIMEOUT_MAX: float

class ThreadError(Exception): ...

class local:
def __getattribute__(self, __name: str) -> Any: ...
def __setattr__(self, __name: str, __value: Any) -> None: ...
def __delattr__(self, __name: str) -> None: ...
ThreadError = _thread.error
local = _thread._local

class Thread:
name: str
Expand Down
5 changes: 2 additions & 3 deletions mypy/typeshed/stdlib/unittest/_log.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ import logging
import sys
from types import TracebackType
from typing import ClassVar, Generic, NamedTuple, TypeVar
from unittest.case import TestCase
from unittest.case import TestCase, _BaseTestCaseContext

_L = TypeVar("_L", None, _LoggingWatcher)

class _LoggingWatcher(NamedTuple):
records: list[logging.LogRecord]
output: list[str]

class _AssertLogsContext(Generic[_L]):
class _AssertLogsContext(_BaseTestCaseContext, Generic[_L]):
LOGGING_FORMAT: ClassVar[str]
test_case: TestCase
logger_name: str
level: int
msg: None
Expand Down
Loading