Skip to content

Commit 8b3b6bf

Browse files
authored
stdlib: Audit Callable[<parameters>, None] annotations (#8187)
1 parent 0178a0e commit 8b3b6bf

21 files changed

+59
-66
lines changed

stdlib/_dummy_threading.pyi

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
import sys
2+
from _typeshed import ProfileFunction, TraceFunction
23
from collections.abc import Callable, Iterable, Mapping
3-
from types import FrameType, TracebackType
4+
from types import TracebackType
45
from typing import Any, TypeVar
5-
from typing_extensions import TypeAlias
66

7-
# TODO recursive type
8-
_TF: TypeAlias = Callable[[FrameType, str, Any], Callable[..., Any] | None]
9-
10-
_PF: TypeAlias = Callable[[FrameType, str, Any], None]
117
_T = TypeVar("_T")
128

139
__all__ = [
@@ -43,8 +39,8 @@ def currentThread() -> Thread: ...
4339
def get_ident() -> int: ...
4440
def enumerate() -> list[Thread]: ...
4541
def main_thread() -> Thread: ...
46-
def settrace(func: _TF) -> None: ...
47-
def setprofile(func: _PF | None) -> None: ...
42+
def settrace(func: TraceFunction) -> None: ...
43+
def setprofile(func: ProfileFunction | None) -> None: ...
4844
def stack_size(size: int = ...) -> int: ...
4945

5046
TIMEOUT_MAX: float

stdlib/_typeshed/__init__.pyi

+9-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import ctypes
77
import mmap
88
import pickle
99
import sys
10-
from collections.abc import Awaitable, Container, Iterable, Set as AbstractSet
10+
from collections.abc import Awaitable, Callable, Container, Iterable, Set as AbstractSet
1111
from os import PathLike
12-
from types import TracebackType
12+
from types import FrameType, TracebackType
1313
from typing import Any, AnyStr, Generic, Protocol, TypeVar, Union
1414
from typing_extensions import Final, Literal, LiteralString, TypeAlias, final
1515

@@ -262,3 +262,10 @@ class structseq(Generic[_T_co]):
262262

263263
# Superset of typing.AnyStr that also inclues LiteralString
264264
AnyOrLiteralStr = TypeVar("AnyOrLiteralStr", str, bytes, LiteralString) # noqa: Y001
265+
266+
# Objects suitable to be passed to sys.setprofile, threading.setprofile, and similar
267+
ProfileFunction: TypeAlias = Callable[[FrameType, str, Any], object]
268+
269+
# Objects suitable to be passed to sys.settrace, threading.settrace, and similar
270+
# TODO: Ideally this would be a recursive type alias
271+
TraceFunction: TypeAlias = Callable[[FrameType, str, Any], Callable[[FrameType, str, Any], Any] | None]

stdlib/asyncio/windows_utils.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ if sys.platform == "win32":
3636
@property
3737
def handle(self) -> int: ...
3838
def fileno(self) -> int: ...
39-
def close(self, *, CloseHandle: Callable[[int], None] = ...) -> None: ...
39+
def close(self, *, CloseHandle: Callable[[int], object] = ...) -> None: ...
4040

4141
class Popen(subprocess.Popen[AnyStr]):
4242
stdin: PipeHandle | None # type: ignore[assignment]

stdlib/concurrent/futures/process.pyi

+4-4
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ if sys.version_info >= (3, 11):
111111
def _process_worker(
112112
call_queue: Queue[_CallItem],
113113
result_queue: SimpleQueue[_ResultItem],
114-
initializer: Callable[..., None] | None,
114+
initializer: Callable[..., object] | None,
115115
initargs: tuple[Any, ...],
116116
max_tasks: int | None = ...,
117117
) -> None: ...
@@ -120,7 +120,7 @@ elif sys.version_info >= (3, 7):
120120
def _process_worker(
121121
call_queue: Queue[_CallItem],
122122
result_queue: SimpleQueue[_ResultItem],
123-
initializer: Callable[..., None] | None,
123+
initializer: Callable[..., object] | None,
124124
initargs: tuple[Any, ...],
125125
) -> None: ...
126126

@@ -184,7 +184,7 @@ class ProcessPoolExecutor(Executor):
184184
self,
185185
max_workers: int | None = ...,
186186
mp_context: BaseContext | None = ...,
187-
initializer: Callable[..., None] | None = ...,
187+
initializer: Callable[..., object] | None = ...,
188188
initargs: tuple[Any, ...] = ...,
189189
*,
190190
max_tasks_per_child: int | None = ...,
@@ -194,7 +194,7 @@ class ProcessPoolExecutor(Executor):
194194
self,
195195
max_workers: int | None = ...,
196196
mp_context: BaseContext | None = ...,
197-
initializer: Callable[..., None] | None = ...,
197+
initializer: Callable[..., object] | None = ...,
198198
initargs: tuple[Any, ...] = ...,
199199
) -> None: ...
200200
else:

stdlib/concurrent/futures/thread.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ if sys.version_info >= (3, 7):
3232
def _worker(
3333
executor_reference: ref[Any],
3434
work_queue: queue.SimpleQueue[Any],
35-
initializer: Callable[..., None],
35+
initializer: Callable[..., object],
3636
initargs: tuple[Any, ...],
3737
) -> None: ...
3838

@@ -63,7 +63,7 @@ class ThreadPoolExecutor(Executor):
6363
self,
6464
max_workers: int | None = ...,
6565
thread_name_prefix: str = ...,
66-
initializer: Callable[..., None] | None = ...,
66+
initializer: Callable[..., object] | None = ...,
6767
initargs: tuple[Any, ...] = ...,
6868
) -> None: ...
6969
else:

stdlib/distutils/ccompiler.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ class CCompiler:
143143
def library_filename(self, libname: str, lib_type: str = ..., strip_dir: int = ..., output_dir: str = ...) -> str: ...
144144
def object_filenames(self, source_filenames: list[str], strip_dir: int = ..., output_dir: str = ...) -> list[str]: ...
145145
def shared_object_filename(self, basename: str, strip_dir: int = ..., output_dir: str = ...) -> str: ...
146-
def execute(self, func: Callable[..., None], args: tuple[Any, ...], msg: str | None = ..., level: int = ...) -> None: ...
146+
def execute(self, func: Callable[..., object], args: tuple[Any, ...], msg: str | None = ..., level: int = ...) -> None: ...
147147
def spawn(self, cmd: list[str]) -> None: ...
148148
def mkpath(self, name: str, mode: int = ...) -> None: ...
149149
def move_file(self, src: str, dst: str) -> str: ...

stdlib/distutils/util.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def check_environ() -> None: ...
1010
def subst_vars(s: str, local_vars: Mapping[str, str]) -> None: ...
1111
def split_quoted(s: str) -> list[str]: ...
1212
def execute(
13-
func: Callable[..., None], args: tuple[Any, ...], msg: str | None = ..., verbose: bool = ..., dry_run: bool = ...
13+
func: Callable[..., object], args: tuple[Any, ...], msg: str | None = ..., verbose: bool = ..., dry_run: bool = ...
1414
) -> None: ...
1515
def strtobool(val: str) -> Literal[0, 1]: ...
1616
def byte_compile(

stdlib/email/mime/application.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class MIMEApplication(MIMENonMultipart):
1010
self,
1111
_data: str | bytes,
1212
_subtype: str = ...,
13-
_encoder: Callable[[MIMEApplication], None] = ...,
13+
_encoder: Callable[[MIMEApplication], object] = ...,
1414
*,
1515
policy: Policy | None = ...,
1616
**_params: _ParamsType,

stdlib/email/mime/audio.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class MIMEAudio(MIMENonMultipart):
1010
self,
1111
_audiodata: str | bytes,
1212
_subtype: str | None = ...,
13-
_encoder: Callable[[MIMEAudio], None] = ...,
13+
_encoder: Callable[[MIMEAudio], object] = ...,
1414
*,
1515
policy: Policy | None = ...,
1616
**_params: _ParamsType,

stdlib/email/mime/image.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class MIMEImage(MIMENonMultipart):
1010
self,
1111
_imagedata: str | bytes,
1212
_subtype: str | None = ...,
13-
_encoder: Callable[[MIMEImage], None] = ...,
13+
_encoder: Callable[[MIMEImage], object] = ...,
1414
*,
1515
policy: Policy | None = ...,
1616
**_params: _ParamsType,

stdlib/lib2to3/pgen2/tokenize.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ if sys.version_info >= (3, 7):
7878
__all__ += ["COLONEQUAL"]
7979

8080
_Coord: TypeAlias = tuple[int, int]
81-
_TokenEater: TypeAlias = Callable[[int, str, _Coord, _Coord, str], None]
81+
_TokenEater: TypeAlias = Callable[[int, str, _Coord, _Coord, str], object]
8282
_TokenInfo: TypeAlias = tuple[int, str, _Coord, _Coord, str]
8383

8484
class TokenError(Exception): ...

stdlib/os/__init__.pyi

+4-4
Original file line numberDiff line numberDiff line change
@@ -213,17 +213,17 @@ class _Environ(MutableMapping[AnyStr, AnyStr], Generic[AnyStr]):
213213
decodevalue: _EnvironCodeFunc[AnyStr],
214214
) -> None: ...
215215
else:
216-
putenv: Callable[[AnyStr, AnyStr], None]
217-
unsetenv: Callable[[AnyStr, AnyStr], None]
216+
putenv: Callable[[AnyStr, AnyStr], object]
217+
unsetenv: Callable[[AnyStr, AnyStr], object]
218218
def __init__(
219219
self,
220220
data: MutableMapping[AnyStr, AnyStr],
221221
encodekey: _EnvironCodeFunc[AnyStr],
222222
decodekey: _EnvironCodeFunc[AnyStr],
223223
encodevalue: _EnvironCodeFunc[AnyStr],
224224
decodevalue: _EnvironCodeFunc[AnyStr],
225-
putenv: Callable[[AnyStr, AnyStr], None],
226-
unsetenv: Callable[[AnyStr, AnyStr], None],
225+
putenv: Callable[[AnyStr, AnyStr], object],
226+
unsetenv: Callable[[AnyStr, AnyStr], object],
227227
) -> None: ...
228228

229229
def setdefault(self, key: AnyStr, value: AnyStr) -> AnyStr: ... # type: ignore[override]

stdlib/pkgutil.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def iter_importers(fullname: str = ...) -> Iterator[MetaPathFinder | PathEntryFi
4141
def iter_modules(path: Iterable[str] | None = ..., prefix: str = ...) -> Iterator[ModuleInfo]: ...
4242
def read_code(stream: SupportsRead[bytes]) -> Any: ... # undocumented
4343
def walk_packages(
44-
path: Iterable[str] | None = ..., prefix: str = ..., onerror: Callable[[str], None] | None = ...
44+
path: Iterable[str] | None = ..., prefix: str = ..., onerror: Callable[[str], object] | None = ...
4545
) -> Iterator[ModuleInfo]: ...
4646
def get_data(package: str, resource: str) -> bytes | None: ...
4747

stdlib/pydoc.pyi

+3-3
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,10 @@ class ModuleScanner:
238238
quit: bool
239239
def run(
240240
self,
241-
callback: Callable[[str | None, str, str], None],
241+
callback: Callable[[str | None, str, str], object],
242242
key: str | None = ...,
243-
completer: Callable[[], None] | None = ...,
244-
onerror: Callable[[str], None] | None = ...,
243+
completer: Callable[[], object] | None = ...,
244+
onerror: Callable[[str], object] | None = ...,
245245
) -> None: ...
246246

247247
def apropos(key: str) -> None: ...

stdlib/shutil.pyi

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ if sys.version_info >= (3, 8):
6767
dst: StrPath,
6868
symlinks: bool = ...,
6969
ignore: None | Callable[[str, list[str]], Iterable[str]] | Callable[[StrPath, list[str]], Iterable[str]] = ...,
70-
copy_function: Callable[[str, str], None] = ...,
70+
copy_function: Callable[[str, str], object] = ...,
7171
ignore_dangling_symlinks: bool = ...,
7272
dirs_exist_ok: bool = ...,
7373
) -> _PathReturn: ...
@@ -78,7 +78,7 @@ else:
7878
dst: StrPath,
7979
symlinks: bool = ...,
8080
ignore: None | Callable[[str, list[str]], Iterable[str]] | Callable[[StrPath, list[str]], Iterable[str]] = ...,
81-
copy_function: Callable[[str, str], None] = ...,
81+
copy_function: Callable[[str, str], object] = ...,
8282
ignore_dangling_symlinks: bool = ...,
8383
) -> _PathReturn: ...
8484

@@ -94,7 +94,7 @@ if sys.version_info >= (3, 11):
9494
else:
9595
def rmtree(path: StrOrBytesPath, ignore_errors: bool = ..., onerror: Callable[[Any, Any, Any], Any] | None = ...) -> None: ...
9696

97-
_CopyFn: TypeAlias = Callable[[str, str], None] | Callable[[StrPath, StrPath], None]
97+
_CopyFn: TypeAlias = Callable[[str, str], object] | Callable[[StrPath, StrPath], object]
9898

9999
# N.B. shutil.move appears to take bytes arguments, however,
100100
# this does not work when dst is (or is within) an existing directory.

stdlib/sys.pyi

+5-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import sys
2-
from _typeshed import OptExcInfo, structseq
2+
from _typeshed import OptExcInfo, ProfileFunction, TraceFunction, structseq
33
from builtins import object as _object
44
from collections.abc import AsyncGenerator, Callable, Coroutine, Sequence
55
from importlib.abc import PathEntryFinder
@@ -241,16 +241,10 @@ def getsizeof(obj: object) -> int: ...
241241
@overload
242242
def getsizeof(obj: object, default: int) -> int: ...
243243
def getswitchinterval() -> float: ...
244-
245-
_ProfileFunc: TypeAlias = Callable[[FrameType, str, Any], Any]
246-
247-
def getprofile() -> _ProfileFunc | None: ...
248-
def setprofile(profilefunc: _ProfileFunc | None) -> None: ...
249-
250-
_TraceFunc: TypeAlias = Callable[[FrameType, str, Any], Callable[[FrameType, str, Any], Any] | None]
251-
252-
def gettrace() -> _TraceFunc | None: ...
253-
def settrace(tracefunc: _TraceFunc | None) -> None: ...
244+
def getprofile() -> ProfileFunction | None: ...
245+
def setprofile(profilefunc: ProfileFunction | None) -> None: ...
246+
def gettrace() -> TraceFunction | None: ...
247+
def settrace(tracefunc: TraceFunction | None) -> None: ...
254248

255249
if sys.platform == "win32":
256250
# A tuple of length 5, even though it has more than 5 attributes.

stdlib/threading.pyi

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
import sys
2+
from _typeshed import ProfileFunction, TraceFunction
23
from collections.abc import Callable, Iterable, Mapping
3-
from types import FrameType, TracebackType
4+
from types import TracebackType
45
from typing import Any, TypeVar
5-
from typing_extensions import TypeAlias
66

7-
# TODO recursive type
8-
_TF: TypeAlias = Callable[[FrameType, str, Any], Callable[..., Any] | None]
9-
10-
_PF: TypeAlias = Callable[[FrameType, str, Any], None]
117
_T = TypeVar("_T")
128

139
__all__ = [
@@ -40,7 +36,7 @@ if sys.version_info >= (3, 8):
4036
if sys.version_info >= (3, 10):
4137
__all__ += ["getprofile", "gettrace"]
4238

43-
_profile_hook: _PF | None
39+
_profile_hook: ProfileFunction | None
4440

4541
def active_count() -> int: ...
4642
def activeCount() -> int: ... # deprecated alias for active_count()
@@ -53,12 +49,12 @@ def main_thread() -> Thread: ...
5349
if sys.version_info >= (3, 8):
5450
from _thread import get_native_id as get_native_id
5551

56-
def settrace(func: _TF) -> None: ...
57-
def setprofile(func: _PF | None) -> None: ...
52+
def settrace(func: TraceFunction) -> None: ...
53+
def setprofile(func: ProfileFunction | None) -> None: ...
5854

5955
if sys.version_info >= (3, 10):
60-
def gettrace() -> _TF | None: ...
61-
def getprofile() -> _PF | None: ...
56+
def gettrace() -> TraceFunction | None: ...
57+
def getprofile() -> ProfileFunction | None: ...
6258

6359
def stack_size(size: int = ...) -> int: ...
6460

stdlib/types.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ if sys.version_info >= (3, 7):
583583
name: str,
584584
bases: Iterable[object] = ...,
585585
kwds: dict[str, Any] | None = ...,
586-
exec_body: Callable[[dict[str, Any]], None] | None = ...,
586+
exec_body: Callable[[dict[str, Any]], object] | None = ...,
587587
) -> type: ...
588588
def resolve_bases(bases: Iterable[object]) -> tuple[Any, ...]: ...
589589

@@ -592,7 +592,7 @@ else:
592592
name: str,
593593
bases: tuple[type, ...] = ...,
594594
kwds: dict[str, Any] | None = ...,
595-
exec_body: Callable[[dict[str, Any]], None] | None = ...,
595+
exec_body: Callable[[dict[str, Any]], object] | None = ...,
596596
) -> type: ...
597597

598598
def prepare_class(

stdlib/unittest/case.pyi

+3-3
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,9 @@ class TestCase:
292292
class FunctionTestCase(TestCase):
293293
def __init__(
294294
self,
295-
testFunc: Callable[[], None],
296-
setUp: Callable[[], None] | None = ...,
297-
tearDown: Callable[[], None] | None = ...,
295+
testFunc: Callable[[], object],
296+
setUp: Callable[[], object] | None = ...,
297+
tearDown: Callable[[], object] | None = ...,
298298
description: str | None = ...,
299299
) -> None: ...
300300
def runTest(self) -> None: ...

stdlib/urllib/request.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ class HTTPErrorProcessor(BaseHandler):
285285
def urlretrieve(
286286
url: str,
287287
filename: StrOrBytesPath | None = ...,
288-
reporthook: Callable[[int, int, int], None] | None = ...,
288+
reporthook: Callable[[int, int, int], object] | None = ...,
289289
data: _DataType = ...,
290290
) -> tuple[str, HTTPMessage]: ...
291291
def urlcleanup() -> None: ...
@@ -299,7 +299,7 @@ class URLopener:
299299
self,
300300
url: str,
301301
filename: str | None = ...,
302-
reporthook: Callable[[int, int, int], None] | None = ...,
302+
reporthook: Callable[[int, int, int], object] | None = ...,
303303
data: bytes | None = ...,
304304
) -> tuple[str, Message | None]: ...
305305
def addheader(self, *args: tuple[str, str]) -> None: ... # undocumented

stdlib/xdrlib.pyi

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ class Packer:
2929
def pack_string(self, s: bytes) -> None: ...
3030
def pack_opaque(self, s: bytes) -> None: ...
3131
def pack_bytes(self, s: bytes) -> None: ...
32-
def pack_list(self, list: Sequence[_T], pack_item: Callable[[_T], None]) -> None: ...
33-
def pack_farray(self, n: int, list: Sequence[_T], pack_item: Callable[[_T], None]) -> None: ...
34-
def pack_array(self, list: Sequence[_T], pack_item: Callable[[_T], None]) -> None: ...
32+
def pack_list(self, list: Sequence[_T], pack_item: Callable[[_T], object]) -> None: ...
33+
def pack_farray(self, n: int, list: Sequence[_T], pack_item: Callable[[_T], object]) -> None: ...
34+
def pack_array(self, list: Sequence[_T], pack_item: Callable[[_T], object]) -> None: ...
3535

3636
class Unpacker:
3737
def __init__(self, data: bytes) -> None: ...

0 commit comments

Comments
 (0)