diff --git a/stdlib/_dummy_thread.pyi b/stdlib/_dummy_thread.pyi index 4cc9b9bc1..463399ca4 100644 --- a/stdlib/_dummy_thread.pyi +++ b/stdlib/_dummy_thread.pyi @@ -7,7 +7,7 @@ __all__ = ["error", "start_new_thread", "exit", "get_ident", "allocate_lock", "i TIMEOUT_MAX: int error = RuntimeError -def start_new_thread(function: Callable[..., Any], args: tuple[Any, ...], kwargs: dict[str, Any] = ...) -> None: ... +def start_new_thread(function: Callable[..., object], args: tuple[Any, ...], kwargs: dict[str, Any] = ...) -> None: ... def exit() -> NoReturn: ... def get_ident() -> int: ... def allocate_lock() -> LockType: ... diff --git a/stdlib/_dummy_threading.pyi b/stdlib/_dummy_threading.pyi index 583127500..c956946c8 100644 --- a/stdlib/_dummy_threading.pyi +++ b/stdlib/_dummy_threading.pyi @@ -60,7 +60,7 @@ class Thread: def __init__( self, group: None = ..., - target: Callable[..., Any] | None = ..., + target: Callable[..., object] | None = ..., name: str | None = ..., args: Iterable[Any] = ..., kwargs: Mapping[str, Any] | None = ..., @@ -151,7 +151,7 @@ class Timer(Thread): def __init__( self, interval: float, - function: Callable[..., Any], + function: Callable[..., object], args: Iterable[Any] | None = ..., kwargs: Mapping[str, Any] | None = ..., ) -> None: ... diff --git a/stdlib/_thread.pyi b/stdlib/_thread.pyi index 10a191cbd..152362edc 100644 --- a/stdlib/_thread.pyi +++ b/stdlib/_thread.pyi @@ -19,7 +19,7 @@ class LockType: self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None ) -> None: ... -def start_new_thread(function: Callable[..., Any], args: tuple[Any, ...], kwargs: dict[str, Any] = ...) -> int: ... +def start_new_thread(function: Callable[..., object], args: tuple[Any, ...], kwargs: dict[str, Any] = ...) -> int: ... def interrupt_main() -> None: ... def exit() -> NoReturn: ... def allocate_lock() -> LockType: ... diff --git a/stdlib/atexit.pyi b/stdlib/atexit.pyi index 095ab5f9b..ea041d7b5 100644 --- a/stdlib/atexit.pyi +++ b/stdlib/atexit.pyi @@ -1,5 +1,5 @@ from collections.abc import Callable -from typing import Any, TypeVar +from typing import TypeVar from typing_extensions import ParamSpec _T = TypeVar("_T") @@ -9,4 +9,4 @@ def _clear() -> None: ... def _ncallbacks() -> int: ... def _run_exitfuncs() -> None: ... def register(func: Callable[_P, _T], *args: _P.args, **kwargs: _P.kwargs) -> Callable[_P, _T]: ... -def unregister(func: Callable[..., Any]) -> None: ... +def unregister(func: Callable[..., object]) -> None: ... diff --git a/stdlib/bdb.pyi b/stdlib/bdb.pyi index f4d1875ef..58808632b 100644 --- a/stdlib/bdb.pyi +++ b/stdlib/bdb.pyi @@ -1,15 +1,14 @@ import sys -from _typeshed import ExcInfo +from _typeshed import ExcInfo, TraceFunction from collections.abc import Callable, Iterable, Mapping from types import CodeType, FrameType, TracebackType from typing import IO, Any, SupportsInt, TypeVar -from typing_extensions import Literal, ParamSpec, TypeAlias +from typing_extensions import Literal, ParamSpec __all__ = ["BdbQuit", "Bdb", "Breakpoint"] _T = TypeVar("_T") _P = ParamSpec("_P") -_TraceDispatch: TypeAlias = Callable[[FrameType, str, Any], Any] # TODO: Recursive type GENERATOR_AND_COROUTINE_FLAGS: Literal[672] @@ -28,11 +27,11 @@ class Bdb: def __init__(self, skip: Iterable[str] | None = ...) -> None: ... def canonic(self, filename: str) -> str: ... def reset(self) -> None: ... - def trace_dispatch(self, frame: FrameType, event: str, arg: Any) -> _TraceDispatch: ... - def dispatch_line(self, frame: FrameType) -> _TraceDispatch: ... - def dispatch_call(self, frame: FrameType, arg: None) -> _TraceDispatch: ... - def dispatch_return(self, frame: FrameType, arg: Any) -> _TraceDispatch: ... - def dispatch_exception(self, frame: FrameType, arg: ExcInfo) -> _TraceDispatch: ... + def trace_dispatch(self, frame: FrameType, event: str, arg: Any) -> TraceFunction: ... + def dispatch_line(self, frame: FrameType) -> TraceFunction: ... + def dispatch_call(self, frame: FrameType, arg: None) -> TraceFunction: ... + def dispatch_return(self, frame: FrameType, arg: Any) -> TraceFunction: ... + def dispatch_exception(self, frame: FrameType, arg: ExcInfo) -> TraceFunction: ... def is_skipped_module(self, module_name: str) -> bool: ... def stop_here(self, frame: FrameType) -> bool: ... def break_here(self, frame: FrameType) -> bool: ... diff --git a/stdlib/concurrent/futures/_base.pyi b/stdlib/concurrent/futures/_base.pyi index 7a1e7e703..9dd9be4d6 100644 --- a/stdlib/concurrent/futures/_base.pyi +++ b/stdlib/concurrent/futures/_base.pyi @@ -49,7 +49,7 @@ class Future(Generic[_T]): def cancelled(self) -> bool: ... def running(self) -> bool: ... def done(self) -> bool: ... - def add_done_callback(self, fn: Callable[[Future[_T]], Any]) -> None: ... + def add_done_callback(self, fn: Callable[[Future[_T]], object]) -> None: ... def result(self, timeout: float | None = ...) -> _T: ... def set_running_or_notify_cancel(self) -> bool: ... def set_result(self, result: _T) -> None: ... diff --git a/stdlib/concurrent/futures/process.pyi b/stdlib/concurrent/futures/process.pyi index e7900aa41..211107cf3 100644 --- a/stdlib/concurrent/futures/process.pyi +++ b/stdlib/concurrent/futures/process.pyi @@ -10,6 +10,8 @@ from weakref import ref from ._base import BrokenExecutor, Executor, Future +_T = TypeVar("_T") + _threads_wakeups: MutableMapping[Any, Any] _global_shutdown: bool @@ -40,14 +42,12 @@ class _ExceptionWithTraceback: def _rebuild_exc(exc: Exception, tb: str) -> Exception: ... -_S = TypeVar("_S") - -class _WorkItem(Generic[_S]): - future: Future[_S] - fn: Callable[..., _S] +class _WorkItem(Generic[_T]): + future: Future[_T] + fn: Callable[..., _T] args: Iterable[Any] kwargs: Mapping[str, Any] - def __init__(self, future: Future[_S], fn: Callable[..., _S], args: Iterable[Any], kwargs: Mapping[str, Any]) -> None: ... + def __init__(self, future: Future[_T], fn: Callable[..., _T], args: Iterable[Any], kwargs: Mapping[str, Any]) -> None: ... class _ResultItem: work_id: int @@ -90,7 +90,7 @@ class _SafeQueue(Queue[Future[Any]]): 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 _process_chunk(fn: Callable[..., _T], chunk: Iterable[tuple[Any, ...]]) -> list[_T]: ... if sys.version_info >= (3, 11): def _sendback_result( diff --git a/stdlib/distutils/cmd.pyi b/stdlib/distutils/cmd.pyi index 8163ae78f..e706bdbc5 100644 --- a/stdlib/distutils/cmd.pyi +++ b/stdlib/distutils/cmd.pyi @@ -25,7 +25,7 @@ class Command: def run_command(self, command: str) -> None: ... def get_sub_commands(self) -> list[str]: ... def warn(self, msg: str) -> None: ... - def execute(self, func: Callable[..., Any], args: Iterable[Any], msg: str | None = ..., level: int = ...) -> None: ... + def execute(self, func: Callable[..., object], args: Iterable[Any], msg: str | None = ..., level: int = ...) -> None: ... def mkpath(self, name: str, mode: int = ...) -> None: ... def copy_file( self, @@ -60,7 +60,7 @@ class Command: self, infiles: str | list[str] | tuple[str, ...], outfile: str, - func: Callable[..., Any], + func: Callable[..., object], args: list[Any], exec_msg: str | None = ..., skip_msg: str | None = ..., diff --git a/stdlib/doctest.pyi b/stdlib/doctest.pyi index c767436c2..6bb1bf9d3 100644 --- a/stdlib/doctest.pyi +++ b/stdlib/doctest.pyi @@ -126,7 +126,7 @@ class DocTestFinder: extraglobs: dict[str, Any] | None = ..., ) -> list[DocTest]: ... -_Out: TypeAlias = Callable[[str], Any] +_Out: TypeAlias = Callable[[str], object] class DocTestRunner: DIVIDER: str @@ -201,8 +201,8 @@ class DocTestCase(unittest.TestCase): self, test: DocTest, optionflags: int = ..., - setUp: Callable[[DocTest], Any] | None = ..., - tearDown: Callable[[DocTest], Any] | None = ..., + setUp: Callable[[DocTest], object] | None = ..., + tearDown: Callable[[DocTest], object] | None = ..., checker: OutputChecker | None = ..., ) -> None: ... def setUp(self) -> None: ... diff --git a/stdlib/ftplib.pyi b/stdlib/ftplib.pyi index 49c680a6f..3d284c597 100644 --- a/stdlib/ftplib.pyi +++ b/stdlib/ftplib.pyi @@ -90,22 +90,22 @@ class FTP: def ntransfercmd(self, cmd: str, rest: int | str | None = ...) -> tuple[socket, int]: ... def transfercmd(self, cmd: str, rest: int | str | None = ...) -> socket: ... def retrbinary( - self, cmd: str, callback: Callable[[bytes], Any], blocksize: int = ..., rest: int | str | None = ... + self, cmd: str, callback: Callable[[bytes], object], blocksize: int = ..., rest: int | str | None = ... ) -> str: ... def storbinary( self, cmd: str, fp: SupportsRead[bytes], blocksize: int = ..., - callback: Callable[[bytes], Any] | None = ..., + callback: Callable[[bytes], object] | None = ..., rest: int | str | None = ..., ) -> str: ... - def retrlines(self, cmd: str, callback: Callable[[str], Any] | None = ...) -> str: ... - def storlines(self, cmd: str, fp: SupportsReadline[bytes], callback: Callable[[bytes], Any] | None = ...) -> str: ... + def retrlines(self, cmd: str, callback: Callable[[str], object] | None = ...) -> str: ... + def storlines(self, cmd: str, fp: SupportsReadline[bytes], callback: Callable[[bytes], object] | None = ...) -> str: ... def acct(self, password: str) -> str: ... def nlst(self, *args: str) -> list[str]: ... # Technically only the last arg can be a Callable but ... - def dir(self, *args: str | Callable[[str], None]) -> None: ... + def dir(self, *args: str | Callable[[str], object]) -> None: ... def mlsd(self, path: str = ..., facts: Iterable[str] = ...) -> Iterator[tuple[str, dict[str, str]]]: ... def rename(self, fromname: str, toname: str) -> str: ... def delete(self, filename: str) -> str: ... diff --git a/stdlib/functools.pyi b/stdlib/functools.pyi index 3003ef061..5c3f662c3 100644 --- a/stdlib/functools.pyi +++ b/stdlib/functools.pyi @@ -28,7 +28,7 @@ if sys.version_info >= (3, 8): if sys.version_info >= (3, 9): __all__ += ["cache"] -_AnyCallable: TypeAlias = Callable[..., Any] +_AnyCallable: TypeAlias = Callable[..., object] _T = TypeVar("_T") _S = TypeVar("_S") diff --git a/stdlib/heapq.pyi b/stdlib/heapq.pyi index f07afc7af..b28032268 100644 --- a/stdlib/heapq.pyi +++ b/stdlib/heapq.pyi @@ -9,7 +9,9 @@ _S = TypeVar("_S") __about__: str -def merge(*iterables: Iterable[_S], key: Callable[[_S], Any] | None = ..., reverse: bool = ...) -> Iterable[_S]: ... +def merge( + *iterables: Iterable[_S], key: Callable[[_S], SupportsRichComparison] | None = ..., reverse: bool = ... +) -> Iterable[_S]: ... def nlargest(n: int, iterable: Iterable[_S], key: Callable[[_S], SupportsRichComparison] | None = ...) -> list[_S]: ... def nsmallest(n: int, iterable: Iterable[_S], key: Callable[[_S], SupportsRichComparison] | None = ...) -> list[_S]: ... def _heapify_max(__x: list[Any]) -> None: ... # undocumented diff --git a/stdlib/lib2to3/pytree.pyi b/stdlib/lib2to3/pytree.pyi index fa0cb9e34..208a87da8 100644 --- a/stdlib/lib2to3/pytree.pyi +++ b/stdlib/lib2to3/pytree.pyi @@ -8,6 +8,8 @@ _NL: TypeAlias = Node | Leaf _Context: TypeAlias = tuple[str, int, int] _Results: TypeAlias = dict[str, _NL] _RawNode: TypeAlias = tuple[int, str, _Context, list[_NL] | None] +# This alias isn't used in this file, +# but is imported in other lib2to3 submodules _Convert: TypeAlias = Callable[[Grammar, _RawNode], Any] HUGE: int diff --git a/stdlib/os/__init__.pyi b/stdlib/os/__init__.pyi index 973d9d094..e3d428555 100644 --- a/stdlib/os/__init__.pyi +++ b/stdlib/os/__init__.pyi @@ -754,7 +754,7 @@ def utime( follow_symlinks: bool = ..., ) -> None: ... -_OnError: TypeAlias = Callable[[OSError], Any] +_OnError: TypeAlias = Callable[[OSError], object] def walk( top: GenericPath[AnyStr], topdown: bool = ..., onerror: _OnError | None = ..., followlinks: bool = ... @@ -974,7 +974,7 @@ if sys.version_info >= (3, 8): if sys.platform == "win32": class _AddedDllDirectory: path: str | None - def __init__(self, path: str | None, cookie: _T, remove_dll_directory: Callable[[_T], Any]) -> None: ... + def __init__(self, path: str | None, cookie: _T, remove_dll_directory: Callable[[_T], object]) -> None: ... def close(self) -> None: ... def __enter__(self: Self) -> Self: ... def __exit__(self, *args: object) -> None: ... diff --git a/stdlib/sched.pyi b/stdlib/sched.pyi index 709d6f47f..29c84f951 100644 --- a/stdlib/sched.pyi +++ b/stdlib/sched.pyi @@ -1,15 +1,18 @@ import sys from collections.abc import Callable from typing import Any, NamedTuple +from typing_extensions import TypeAlias __all__ = ["scheduler"] +_ActionCallback: TypeAlias = Callable[..., Any] + if sys.version_info >= (3, 10): class Event(NamedTuple): time: float priority: Any sequence: int - action: Callable[..., Any] + action: _ActionCallback argument: tuple[Any, ...] kwargs: dict[str, Any] @@ -17,7 +20,7 @@ else: class Event(NamedTuple): time: float priority: Any - action: Callable[..., Any] + action: _ActionCallback argument: tuple[Any, ...] kwargs: dict[str, Any] @@ -27,20 +30,10 @@ class scheduler: def __init__(self, timefunc: Callable[[], float] = ..., delayfunc: Callable[[float], object] = ...) -> None: ... def enterabs( - self, - time: float, - priority: Any, - action: Callable[..., Any], - argument: tuple[Any, ...] = ..., - kwargs: dict[str, Any] = ..., + self, time: float, priority: Any, action: _ActionCallback, argument: tuple[Any, ...] = ..., kwargs: dict[str, Any] = ... ) -> Event: ... def enter( - self, - delay: float, - priority: Any, - action: Callable[..., Any], - argument: tuple[Any, ...] = ..., - kwargs: dict[str, Any] = ..., + self, delay: float, priority: Any, action: _ActionCallback, argument: tuple[Any, ...] = ..., kwargs: dict[str, Any] = ... ) -> Event: ... def run(self, blocking: bool = ...) -> float | None: ... def cancel(self, event: Event) -> None: ... diff --git a/stdlib/shutil.pyi b/stdlib/shutil.pyi index 7b60bf04e..13c706de1 100644 --- a/stdlib/shutil.pyi +++ b/stdlib/shutil.pyi @@ -82,17 +82,15 @@ else: ignore_dangling_symlinks: bool = ..., ) -> _PathReturn: ... +_OnErrorCallback: TypeAlias = Callable[[Callable[..., Any], Any, Any], object] + if sys.version_info >= (3, 11): def rmtree( - path: StrOrBytesPath, - ignore_errors: bool = ..., - onerror: Callable[[Any, Any, Any], Any] | None = ..., - *, - dir_fd: int | None = ..., + path: StrOrBytesPath, ignore_errors: bool = ..., onerror: _OnErrorCallback | None = ..., *, dir_fd: int | None = ... ) -> None: ... else: - def rmtree(path: StrOrBytesPath, ignore_errors: bool = ..., onerror: Callable[[Any, Any, Any], Any] | None = ...) -> None: ... + def rmtree(path: StrOrBytesPath, ignore_errors: bool = ..., onerror: _OnErrorCallback | None = ...) -> None: ... _CopyFn: TypeAlias = Callable[[str, str], object] | Callable[[StrPath, StrPath], object] diff --git a/stdlib/telnetlib.pyi b/stdlib/telnetlib.pyi index 5a4326c4a..67ae5fcc8 100644 --- a/stdlib/telnetlib.pyi +++ b/stdlib/telnetlib.pyi @@ -104,7 +104,7 @@ class Telnet: def read_lazy(self) -> bytes: ... def read_very_lazy(self) -> bytes: ... def read_sb_data(self) -> bytes: ... - def set_option_negotiation_callback(self, callback: Callable[[socket.socket, bytes, bytes], Any] | None) -> None: ... + def set_option_negotiation_callback(self, callback: Callable[[socket.socket, bytes, bytes], object] | None) -> None: ... def process_rawq(self) -> None: ... def rawq_getchar(self) -> bytes: ... def fill_rawq(self) -> None: ... diff --git a/stdlib/threading.pyi b/stdlib/threading.pyi index 0b0961c05..289a86826 100644 --- a/stdlib/threading.pyi +++ b/stdlib/threading.pyi @@ -75,7 +75,7 @@ class Thread: def __init__( self, group: None = ..., - target: Callable[..., Any] | None = ..., + target: Callable[..., object] | None = ..., name: str | None = ..., args: Iterable[Any] = ..., kwargs: Mapping[str, Any] | None = ..., @@ -171,7 +171,7 @@ class Timer(Thread): def __init__( self, interval: float, - function: Callable[..., Any], + function: Callable[..., object], args: Iterable[Any] | None = ..., kwargs: Mapping[str, Any] | None = ..., ) -> None: ... diff --git a/stdlib/timeit.pyi b/stdlib/timeit.pyi index 076b2c54f..dda6cefed 100644 --- a/stdlib/timeit.pyi +++ b/stdlib/timeit.pyi @@ -5,7 +5,7 @@ from typing_extensions import TypeAlias __all__ = ["Timer", "timeit", "repeat", "default_timer"] _Timer: TypeAlias = Callable[[], float] -_Stmt: TypeAlias = str | Callable[[], Any] +_Stmt: TypeAlias = str | Callable[[], object] default_timer: _Timer @@ -16,7 +16,7 @@ class Timer: def print_exc(self, file: IO[str] | None = ...) -> None: ... def timeit(self, number: int = ...) -> float: ... def repeat(self, repeat: int = ..., number: int = ...) -> list[float]: ... - def autorange(self, callback: Callable[[int, float], Any] | None = ...) -> tuple[int, float]: ... + def autorange(self, callback: Callable[[int, float], object] | None = ...) -> tuple[int, float]: ... def timeit( stmt: _Stmt = ..., setup: _Stmt = ..., timer: _Timer = ..., number: int = ..., globals: dict[str, Any] | None = ... diff --git a/stdlib/wsgiref/validate.pyi b/stdlib/wsgiref/validate.pyi index ada2283a6..4fb18d830 100644 --- a/stdlib/wsgiref/validate.pyi +++ b/stdlib/wsgiref/validate.pyi @@ -1,6 +1,7 @@ from _typeshed.wsgi import ErrorStream, InputStream, WSGIApplication from collections.abc import Callable, Iterable, Iterator from typing import Any, NoReturn +from typing_extensions import TypeAlias __all__ = ["validator"] @@ -25,9 +26,11 @@ class ErrorWrapper: def writelines(self, seq: Iterable[str]) -> None: ... def close(self) -> NoReturn: ... +_WriterCallback: TypeAlias = Callable[[bytes], Any] + class WriteWrapper: - writer: Callable[[bytes], Any] - def __init__(self, wsgi_writer: Callable[[bytes], Any]) -> None: ... + writer: _WriterCallback + def __init__(self, wsgi_writer: _WriterCallback) -> None: ... def __call__(self, s: bytes) -> None: ... class PartialIteratorWrapper: diff --git a/stdlib/xml/etree/ElementTree.pyi b/stdlib/xml/etree/ElementTree.pyi index 82cd735bd..84059bc21 100644 --- a/stdlib/xml/etree/ElementTree.pyi +++ b/stdlib/xml/etree/ElementTree.pyi @@ -325,7 +325,7 @@ if sys.version_info >= (3, 8): class C14NWriterTarget: def __init__( self, - write: Callable[[str], Any], + write: Callable[[str], object], *, with_comments: bool = ..., strip_text: bool = ...,