Skip to content

Commit 8b3b6bf

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

File tree

21 files changed

+59
-66
lines changed

21 files changed

+59
-66
lines changed

stdlib/_dummy_threading.pyi

Lines changed: 4 additions & 8 deletions
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

Lines changed: 9 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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,

0 commit comments

Comments
 (0)