diff --git a/stdlib/_dummy_threading.pyi b/stdlib/_dummy_threading.pyi index 6f888b3dda70..583127500be8 100644 --- a/stdlib/_dummy_threading.pyi +++ b/stdlib/_dummy_threading.pyi @@ -1,13 +1,9 @@ import sys +from _typeshed import ProfileFunction, TraceFunction from collections.abc import Callable, Iterable, Mapping -from types import FrameType, TracebackType +from types import TracebackType from typing import Any, TypeVar -from typing_extensions import TypeAlias -# TODO recursive type -_TF: TypeAlias = Callable[[FrameType, str, Any], Callable[..., Any] | None] - -_PF: TypeAlias = Callable[[FrameType, str, Any], None] _T = TypeVar("_T") __all__ = [ @@ -43,8 +39,8 @@ def currentThread() -> Thread: ... def get_ident() -> int: ... def enumerate() -> list[Thread]: ... def main_thread() -> Thread: ... -def settrace(func: _TF) -> None: ... -def setprofile(func: _PF | None) -> None: ... +def settrace(func: TraceFunction) -> None: ... +def setprofile(func: ProfileFunction | None) -> None: ... def stack_size(size: int = ...) -> int: ... TIMEOUT_MAX: float diff --git a/stdlib/_typeshed/__init__.pyi b/stdlib/_typeshed/__init__.pyi index bdaf88feb2db..30d800d6f7b3 100644 --- a/stdlib/_typeshed/__init__.pyi +++ b/stdlib/_typeshed/__init__.pyi @@ -7,9 +7,9 @@ import ctypes import mmap import pickle import sys -from collections.abc import Awaitable, Container, Iterable, Set as AbstractSet +from collections.abc import Awaitable, Callable, Container, Iterable, Set as AbstractSet from os import PathLike -from types import TracebackType +from types import FrameType, TracebackType from typing import Any, AnyStr, Generic, Protocol, TypeVar, Union from typing_extensions import Final, Literal, LiteralString, TypeAlias, final @@ -262,3 +262,10 @@ class structseq(Generic[_T_co]): # Superset of typing.AnyStr that also inclues LiteralString AnyOrLiteralStr = TypeVar("AnyOrLiteralStr", str, bytes, LiteralString) # noqa: Y001 + +# Objects suitable to be passed to sys.setprofile, threading.setprofile, and similar +ProfileFunction: TypeAlias = Callable[[FrameType, str, Any], object] + +# Objects suitable to be passed to sys.settrace, threading.settrace, and similar +# TODO: Ideally this would be a recursive type alias +TraceFunction: TypeAlias = Callable[[FrameType, str, Any], Callable[[FrameType, str, Any], Any] | None] diff --git a/stdlib/asyncio/windows_utils.pyi b/stdlib/asyncio/windows_utils.pyi index 0a79635b3d4e..db34356cd16d 100644 --- a/stdlib/asyncio/windows_utils.pyi +++ b/stdlib/asyncio/windows_utils.pyi @@ -36,7 +36,7 @@ if sys.platform == "win32": @property def handle(self) -> int: ... def fileno(self) -> int: ... - def close(self, *, CloseHandle: Callable[[int], None] = ...) -> None: ... + def close(self, *, CloseHandle: Callable[[int], object] = ...) -> None: ... class Popen(subprocess.Popen[AnyStr]): stdin: PipeHandle | None # type: ignore[assignment] diff --git a/stdlib/concurrent/futures/process.pyi b/stdlib/concurrent/futures/process.pyi index 1dd2ee0a6105..0c3bea26c31f 100644 --- a/stdlib/concurrent/futures/process.pyi +++ b/stdlib/concurrent/futures/process.pyi @@ -111,7 +111,7 @@ if sys.version_info >= (3, 11): def _process_worker( call_queue: Queue[_CallItem], result_queue: SimpleQueue[_ResultItem], - initializer: Callable[..., None] | None, + initializer: Callable[..., object] | None, initargs: tuple[Any, ...], max_tasks: int | None = ..., ) -> None: ... @@ -120,7 +120,7 @@ elif sys.version_info >= (3, 7): def _process_worker( call_queue: Queue[_CallItem], result_queue: SimpleQueue[_ResultItem], - initializer: Callable[..., None] | None, + initializer: Callable[..., object] | None, initargs: tuple[Any, ...], ) -> None: ... @@ -184,7 +184,7 @@ class ProcessPoolExecutor(Executor): self, max_workers: int | None = ..., mp_context: BaseContext | None = ..., - initializer: Callable[..., None] | None = ..., + initializer: Callable[..., object] | None = ..., initargs: tuple[Any, ...] = ..., *, max_tasks_per_child: int | None = ..., @@ -194,7 +194,7 @@ class ProcessPoolExecutor(Executor): self, max_workers: int | None = ..., mp_context: BaseContext | None = ..., - initializer: Callable[..., None] | None = ..., + initializer: Callable[..., object] | None = ..., initargs: tuple[Any, ...] = ..., ) -> None: ... else: diff --git a/stdlib/concurrent/futures/thread.pyi b/stdlib/concurrent/futures/thread.pyi index e10254531788..3579c17dbc6c 100644 --- a/stdlib/concurrent/futures/thread.pyi +++ b/stdlib/concurrent/futures/thread.pyi @@ -32,7 +32,7 @@ if sys.version_info >= (3, 7): def _worker( executor_reference: ref[Any], work_queue: queue.SimpleQueue[Any], - initializer: Callable[..., None], + initializer: Callable[..., object], initargs: tuple[Any, ...], ) -> None: ... @@ -63,7 +63,7 @@ class ThreadPoolExecutor(Executor): self, max_workers: int | None = ..., thread_name_prefix: str = ..., - initializer: Callable[..., None] | None = ..., + initializer: Callable[..., object] | None = ..., initargs: tuple[Any, ...] = ..., ) -> None: ... else: diff --git a/stdlib/distutils/ccompiler.pyi b/stdlib/distutils/ccompiler.pyi index ed823f7c070f..5b92c5f5c42e 100644 --- a/stdlib/distutils/ccompiler.pyi +++ b/stdlib/distutils/ccompiler.pyi @@ -143,7 +143,7 @@ class CCompiler: def library_filename(self, libname: str, lib_type: str = ..., strip_dir: int = ..., output_dir: str = ...) -> str: ... def object_filenames(self, source_filenames: list[str], strip_dir: int = ..., output_dir: str = ...) -> list[str]: ... def shared_object_filename(self, basename: str, strip_dir: int = ..., output_dir: str = ...) -> str: ... - def execute(self, func: Callable[..., None], args: tuple[Any, ...], msg: str | None = ..., level: int = ...) -> None: ... + def execute(self, func: Callable[..., object], args: tuple[Any, ...], msg: str | None = ..., level: int = ...) -> None: ... def spawn(self, cmd: list[str]) -> None: ... def mkpath(self, name: str, mode: int = ...) -> None: ... def move_file(self, src: str, dst: str) -> str: ... diff --git a/stdlib/distutils/util.pyi b/stdlib/distutils/util.pyi index 22d982e6949d..da8d66063536 100644 --- a/stdlib/distutils/util.pyi +++ b/stdlib/distutils/util.pyi @@ -10,7 +10,7 @@ def check_environ() -> None: ... def subst_vars(s: str, local_vars: Mapping[str, str]) -> None: ... def split_quoted(s: str) -> list[str]: ... def execute( - func: Callable[..., None], args: tuple[Any, ...], msg: str | None = ..., verbose: bool = ..., dry_run: bool = ... + func: Callable[..., object], args: tuple[Any, ...], msg: str | None = ..., verbose: bool = ..., dry_run: bool = ... ) -> None: ... def strtobool(val: str) -> Literal[0, 1]: ... def byte_compile( diff --git a/stdlib/email/mime/application.pyi b/stdlib/email/mime/application.pyi index 4966a17d9471..dfff85265ade 100644 --- a/stdlib/email/mime/application.pyi +++ b/stdlib/email/mime/application.pyi @@ -10,7 +10,7 @@ class MIMEApplication(MIMENonMultipart): self, _data: str | bytes, _subtype: str = ..., - _encoder: Callable[[MIMEApplication], None] = ..., + _encoder: Callable[[MIMEApplication], object] = ..., *, policy: Policy | None = ..., **_params: _ParamsType, diff --git a/stdlib/email/mime/audio.pyi b/stdlib/email/mime/audio.pyi index fd107d7fcbc6..b355d55070ad 100644 --- a/stdlib/email/mime/audio.pyi +++ b/stdlib/email/mime/audio.pyi @@ -10,7 +10,7 @@ class MIMEAudio(MIMENonMultipart): self, _audiodata: str | bytes, _subtype: str | None = ..., - _encoder: Callable[[MIMEAudio], None] = ..., + _encoder: Callable[[MIMEAudio], object] = ..., *, policy: Policy | None = ..., **_params: _ParamsType, diff --git a/stdlib/email/mime/image.pyi b/stdlib/email/mime/image.pyi index 480f6dcab34b..f575103de2d6 100644 --- a/stdlib/email/mime/image.pyi +++ b/stdlib/email/mime/image.pyi @@ -10,7 +10,7 @@ class MIMEImage(MIMENonMultipart): self, _imagedata: str | bytes, _subtype: str | None = ..., - _encoder: Callable[[MIMEImage], None] = ..., + _encoder: Callable[[MIMEImage], object] = ..., *, policy: Policy | None = ..., **_params: _ParamsType, diff --git a/stdlib/lib2to3/pgen2/tokenize.pyi b/stdlib/lib2to3/pgen2/tokenize.pyi index 34df53994c92..e9da31ed1a0a 100644 --- a/stdlib/lib2to3/pgen2/tokenize.pyi +++ b/stdlib/lib2to3/pgen2/tokenize.pyi @@ -78,7 +78,7 @@ if sys.version_info >= (3, 7): __all__ += ["COLONEQUAL"] _Coord: TypeAlias = tuple[int, int] -_TokenEater: TypeAlias = Callable[[int, str, _Coord, _Coord, str], None] +_TokenEater: TypeAlias = Callable[[int, str, _Coord, _Coord, str], object] _TokenInfo: TypeAlias = tuple[int, str, _Coord, _Coord, str] class TokenError(Exception): ... diff --git a/stdlib/os/__init__.pyi b/stdlib/os/__init__.pyi index 68ea2948f17e..68c7634272e3 100644 --- a/stdlib/os/__init__.pyi +++ b/stdlib/os/__init__.pyi @@ -213,8 +213,8 @@ class _Environ(MutableMapping[AnyStr, AnyStr], Generic[AnyStr]): decodevalue: _EnvironCodeFunc[AnyStr], ) -> None: ... else: - putenv: Callable[[AnyStr, AnyStr], None] - unsetenv: Callable[[AnyStr, AnyStr], None] + putenv: Callable[[AnyStr, AnyStr], object] + unsetenv: Callable[[AnyStr, AnyStr], object] def __init__( self, data: MutableMapping[AnyStr, AnyStr], @@ -222,8 +222,8 @@ class _Environ(MutableMapping[AnyStr, AnyStr], Generic[AnyStr]): decodekey: _EnvironCodeFunc[AnyStr], encodevalue: _EnvironCodeFunc[AnyStr], decodevalue: _EnvironCodeFunc[AnyStr], - putenv: Callable[[AnyStr, AnyStr], None], - unsetenv: Callable[[AnyStr, AnyStr], None], + putenv: Callable[[AnyStr, AnyStr], object], + unsetenv: Callable[[AnyStr, AnyStr], object], ) -> None: ... def setdefault(self, key: AnyStr, value: AnyStr) -> AnyStr: ... # type: ignore[override] diff --git a/stdlib/pkgutil.pyi b/stdlib/pkgutil.pyi index 5a93a9f86812..f91ab78ff35d 100644 --- a/stdlib/pkgutil.pyi +++ b/stdlib/pkgutil.pyi @@ -41,7 +41,7 @@ def iter_importers(fullname: str = ...) -> Iterator[MetaPathFinder | PathEntryFi def iter_modules(path: Iterable[str] | None = ..., prefix: str = ...) -> Iterator[ModuleInfo]: ... def read_code(stream: SupportsRead[bytes]) -> Any: ... # undocumented def walk_packages( - path: Iterable[str] | None = ..., prefix: str = ..., onerror: Callable[[str], None] | None = ... + path: Iterable[str] | None = ..., prefix: str = ..., onerror: Callable[[str], object] | None = ... ) -> Iterator[ModuleInfo]: ... def get_data(package: str, resource: str) -> bytes | None: ... diff --git a/stdlib/pydoc.pyi b/stdlib/pydoc.pyi index 6ea4a74a9d28..1cad4b2def11 100644 --- a/stdlib/pydoc.pyi +++ b/stdlib/pydoc.pyi @@ -238,10 +238,10 @@ class ModuleScanner: quit: bool def run( self, - callback: Callable[[str | None, str, str], None], + callback: Callable[[str | None, str, str], object], key: str | None = ..., - completer: Callable[[], None] | None = ..., - onerror: Callable[[str], None] | None = ..., + completer: Callable[[], object] | None = ..., + onerror: Callable[[str], object] | None = ..., ) -> None: ... def apropos(key: str) -> None: ... diff --git a/stdlib/shutil.pyi b/stdlib/shutil.pyi index ae62ea4b658f..b6d0b9dbf7f3 100644 --- a/stdlib/shutil.pyi +++ b/stdlib/shutil.pyi @@ -67,7 +67,7 @@ if sys.version_info >= (3, 8): dst: StrPath, symlinks: bool = ..., ignore: None | Callable[[str, list[str]], Iterable[str]] | Callable[[StrPath, list[str]], Iterable[str]] = ..., - copy_function: Callable[[str, str], None] = ..., + copy_function: Callable[[str, str], object] = ..., ignore_dangling_symlinks: bool = ..., dirs_exist_ok: bool = ..., ) -> _PathReturn: ... @@ -78,7 +78,7 @@ else: dst: StrPath, symlinks: bool = ..., ignore: None | Callable[[str, list[str]], Iterable[str]] | Callable[[StrPath, list[str]], Iterable[str]] = ..., - copy_function: Callable[[str, str], None] = ..., + copy_function: Callable[[str, str], object] = ..., ignore_dangling_symlinks: bool = ..., ) -> _PathReturn: ... @@ -94,7 +94,7 @@ if sys.version_info >= (3, 11): else: def rmtree(path: StrOrBytesPath, ignore_errors: bool = ..., onerror: Callable[[Any, Any, Any], Any] | None = ...) -> None: ... -_CopyFn: TypeAlias = Callable[[str, str], None] | Callable[[StrPath, StrPath], None] +_CopyFn: TypeAlias = Callable[[str, str], object] | Callable[[StrPath, StrPath], object] # N.B. shutil.move appears to take bytes arguments, however, # this does not work when dst is (or is within) an existing directory. diff --git a/stdlib/sys.pyi b/stdlib/sys.pyi index 667b7024fe12..a66adf23dff8 100644 --- a/stdlib/sys.pyi +++ b/stdlib/sys.pyi @@ -1,5 +1,5 @@ import sys -from _typeshed import OptExcInfo, structseq +from _typeshed import OptExcInfo, ProfileFunction, TraceFunction, structseq from builtins import object as _object from collections.abc import AsyncGenerator, Callable, Coroutine, Sequence from importlib.abc import PathEntryFinder @@ -241,16 +241,10 @@ def getsizeof(obj: object) -> int: ... @overload def getsizeof(obj: object, default: int) -> int: ... def getswitchinterval() -> float: ... - -_ProfileFunc: TypeAlias = Callable[[FrameType, str, Any], Any] - -def getprofile() -> _ProfileFunc | None: ... -def setprofile(profilefunc: _ProfileFunc | None) -> None: ... - -_TraceFunc: TypeAlias = Callable[[FrameType, str, Any], Callable[[FrameType, str, Any], Any] | None] - -def gettrace() -> _TraceFunc | None: ... -def settrace(tracefunc: _TraceFunc | None) -> None: ... +def getprofile() -> ProfileFunction | None: ... +def setprofile(profilefunc: ProfileFunction | None) -> None: ... +def gettrace() -> TraceFunction | None: ... +def settrace(tracefunc: TraceFunction | None) -> None: ... if sys.platform == "win32": # A tuple of length 5, even though it has more than 5 attributes. diff --git a/stdlib/threading.pyi b/stdlib/threading.pyi index afc37b771e8c..729def005831 100644 --- a/stdlib/threading.pyi +++ b/stdlib/threading.pyi @@ -1,13 +1,9 @@ import sys +from _typeshed import ProfileFunction, TraceFunction from collections.abc import Callable, Iterable, Mapping -from types import FrameType, TracebackType +from types import TracebackType from typing import Any, TypeVar -from typing_extensions import TypeAlias -# TODO recursive type -_TF: TypeAlias = Callable[[FrameType, str, Any], Callable[..., Any] | None] - -_PF: TypeAlias = Callable[[FrameType, str, Any], None] _T = TypeVar("_T") __all__ = [ @@ -40,7 +36,7 @@ if sys.version_info >= (3, 8): if sys.version_info >= (3, 10): __all__ += ["getprofile", "gettrace"] -_profile_hook: _PF | None +_profile_hook: ProfileFunction | None def active_count() -> int: ... def activeCount() -> int: ... # deprecated alias for active_count() @@ -53,12 +49,12 @@ def main_thread() -> Thread: ... if sys.version_info >= (3, 8): from _thread import get_native_id as get_native_id -def settrace(func: _TF) -> None: ... -def setprofile(func: _PF | None) -> None: ... +def settrace(func: TraceFunction) -> None: ... +def setprofile(func: ProfileFunction | None) -> None: ... if sys.version_info >= (3, 10): - def gettrace() -> _TF | None: ... - def getprofile() -> _PF | None: ... + def gettrace() -> TraceFunction | None: ... + def getprofile() -> ProfileFunction | None: ... def stack_size(size: int = ...) -> int: ... diff --git a/stdlib/types.pyi b/stdlib/types.pyi index de8c8423d47e..ecd42dbe3ba3 100644 --- a/stdlib/types.pyi +++ b/stdlib/types.pyi @@ -583,7 +583,7 @@ if sys.version_info >= (3, 7): name: str, bases: Iterable[object] = ..., kwds: dict[str, Any] | None = ..., - exec_body: Callable[[dict[str, Any]], None] | None = ..., + exec_body: Callable[[dict[str, Any]], object] | None = ..., ) -> type: ... def resolve_bases(bases: Iterable[object]) -> tuple[Any, ...]: ... @@ -592,7 +592,7 @@ else: name: str, bases: tuple[type, ...] = ..., kwds: dict[str, Any] | None = ..., - exec_body: Callable[[dict[str, Any]], None] | None = ..., + exec_body: Callable[[dict[str, Any]], object] | None = ..., ) -> type: ... def prepare_class( diff --git a/stdlib/unittest/case.pyi b/stdlib/unittest/case.pyi index 6a162f6df1f4..48782f4d4b8d 100644 --- a/stdlib/unittest/case.pyi +++ b/stdlib/unittest/case.pyi @@ -292,9 +292,9 @@ class TestCase: class FunctionTestCase(TestCase): def __init__( self, - testFunc: Callable[[], None], - setUp: Callable[[], None] | None = ..., - tearDown: Callable[[], None] | None = ..., + testFunc: Callable[[], object], + setUp: Callable[[], object] | None = ..., + tearDown: Callable[[], object] | None = ..., description: str | None = ..., ) -> None: ... def runTest(self) -> None: ... diff --git a/stdlib/urllib/request.pyi b/stdlib/urllib/request.pyi index c1805cf6ee82..c44e5cf7043c 100644 --- a/stdlib/urllib/request.pyi +++ b/stdlib/urllib/request.pyi @@ -285,7 +285,7 @@ class HTTPErrorProcessor(BaseHandler): def urlretrieve( url: str, filename: StrOrBytesPath | None = ..., - reporthook: Callable[[int, int, int], None] | None = ..., + reporthook: Callable[[int, int, int], object] | None = ..., data: _DataType = ..., ) -> tuple[str, HTTPMessage]: ... def urlcleanup() -> None: ... @@ -299,7 +299,7 @@ class URLopener: self, url: str, filename: str | None = ..., - reporthook: Callable[[int, int, int], None] | None = ..., + reporthook: Callable[[int, int, int], object] | None = ..., data: bytes | None = ..., ) -> tuple[str, Message | None]: ... def addheader(self, *args: tuple[str, str]) -> None: ... # undocumented diff --git a/stdlib/xdrlib.pyi b/stdlib/xdrlib.pyi index e6b78d5542be..e0b8c6a54b00 100644 --- a/stdlib/xdrlib.pyi +++ b/stdlib/xdrlib.pyi @@ -29,9 +29,9 @@ class Packer: def pack_string(self, s: bytes) -> None: ... def pack_opaque(self, s: bytes) -> None: ... def pack_bytes(self, s: bytes) -> None: ... - def pack_list(self, list: Sequence[_T], pack_item: Callable[[_T], None]) -> None: ... - def pack_farray(self, n: int, list: Sequence[_T], pack_item: Callable[[_T], None]) -> None: ... - def pack_array(self, list: Sequence[_T], pack_item: Callable[[_T], None]) -> None: ... + def pack_list(self, list: Sequence[_T], pack_item: Callable[[_T], object]) -> None: ... + def pack_farray(self, n: int, list: Sequence[_T], pack_item: Callable[[_T], object]) -> None: ... + def pack_array(self, list: Sequence[_T], pack_item: Callable[[_T], object]) -> None: ... class Unpacker: def __init__(self, data: bytes) -> None: ...