stdlib: Audit Callable[<parameters>, None] annotations (#8187)

This commit is contained in:
Alex Waygood
2022-06-27 07:08:28 +01:00
committed by GitHub
parent 0178a0e742
commit 8b3b6bf7cd
21 changed files with 59 additions and 66 deletions

View File

@@ -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

View File

@@ -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]

View File

@@ -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]

View File

@@ -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:

View File

@@ -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:

View File

@@ -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: ...

View File

@@ -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(

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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): ...

View File

@@ -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]

View File

@@ -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: ...

View File

@@ -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: ...

View File

@@ -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.

View File

@@ -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.

View File

@@ -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: ...

View File

@@ -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(

View File

@@ -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: ...

View File

@@ -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

View File

@@ -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: ...