Skip to content

Commit e2ce7c6

Browse files
authored
stdlib: audit more callback annotations (#8209)
1 parent 540a6b2 commit e2ce7c6

21 files changed

+61
-64
lines changed

stdlib/_dummy_thread.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ __all__ = ["error", "start_new_thread", "exit", "get_ident", "allocate_lock", "i
77
TIMEOUT_MAX: int
88
error = RuntimeError
99

10-
def start_new_thread(function: Callable[..., Any], args: tuple[Any, ...], kwargs: dict[str, Any] = ...) -> None: ...
10+
def start_new_thread(function: Callable[..., object], args: tuple[Any, ...], kwargs: dict[str, Any] = ...) -> None: ...
1111
def exit() -> NoReturn: ...
1212
def get_ident() -> int: ...
1313
def allocate_lock() -> LockType: ...

stdlib/_dummy_threading.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class Thread:
6060
def __init__(
6161
self,
6262
group: None = ...,
63-
target: Callable[..., Any] | None = ...,
63+
target: Callable[..., object] | None = ...,
6464
name: str | None = ...,
6565
args: Iterable[Any] = ...,
6666
kwargs: Mapping[str, Any] | None = ...,
@@ -151,7 +151,7 @@ class Timer(Thread):
151151
def __init__(
152152
self,
153153
interval: float,
154-
function: Callable[..., Any],
154+
function: Callable[..., object],
155155
args: Iterable[Any] | None = ...,
156156
kwargs: Mapping[str, Any] | None = ...,
157157
) -> None: ...

stdlib/_thread.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class LockType:
1919
self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
2020
) -> None: ...
2121

22-
def start_new_thread(function: Callable[..., Any], args: tuple[Any, ...], kwargs: dict[str, Any] = ...) -> int: ...
22+
def start_new_thread(function: Callable[..., object], args: tuple[Any, ...], kwargs: dict[str, Any] = ...) -> int: ...
2323
def interrupt_main() -> None: ...
2424
def exit() -> NoReturn: ...
2525
def allocate_lock() -> LockType: ...

stdlib/atexit.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from collections.abc import Callable
2-
from typing import Any, TypeVar
2+
from typing import TypeVar
33
from typing_extensions import ParamSpec
44

55
_T = TypeVar("_T")
@@ -9,4 +9,4 @@ def _clear() -> None: ...
99
def _ncallbacks() -> int: ...
1010
def _run_exitfuncs() -> None: ...
1111
def register(func: Callable[_P, _T], *args: _P.args, **kwargs: _P.kwargs) -> Callable[_P, _T]: ...
12-
def unregister(func: Callable[..., Any]) -> None: ...
12+
def unregister(func: Callable[..., object]) -> None: ...

stdlib/bdb.pyi

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import sys
2-
from _typeshed import ExcInfo
2+
from _typeshed import ExcInfo, TraceFunction
33
from collections.abc import Callable, Iterable, Mapping
44
from types import CodeType, FrameType, TracebackType
55
from typing import IO, Any, SupportsInt, TypeVar
6-
from typing_extensions import Literal, ParamSpec, TypeAlias
6+
from typing_extensions import Literal, ParamSpec
77

88
__all__ = ["BdbQuit", "Bdb", "Breakpoint"]
99

1010
_T = TypeVar("_T")
1111
_P = ParamSpec("_P")
12-
_TraceDispatch: TypeAlias = Callable[[FrameType, str, Any], Any] # TODO: Recursive type
1312

1413
GENERATOR_AND_COROUTINE_FLAGS: Literal[672]
1514

@@ -28,11 +27,11 @@ class Bdb:
2827
def __init__(self, skip: Iterable[str] | None = ...) -> None: ...
2928
def canonic(self, filename: str) -> str: ...
3029
def reset(self) -> None: ...
31-
def trace_dispatch(self, frame: FrameType, event: str, arg: Any) -> _TraceDispatch: ...
32-
def dispatch_line(self, frame: FrameType) -> _TraceDispatch: ...
33-
def dispatch_call(self, frame: FrameType, arg: None) -> _TraceDispatch: ...
34-
def dispatch_return(self, frame: FrameType, arg: Any) -> _TraceDispatch: ...
35-
def dispatch_exception(self, frame: FrameType, arg: ExcInfo) -> _TraceDispatch: ...
30+
def trace_dispatch(self, frame: FrameType, event: str, arg: Any) -> TraceFunction: ...
31+
def dispatch_line(self, frame: FrameType) -> TraceFunction: ...
32+
def dispatch_call(self, frame: FrameType, arg: None) -> TraceFunction: ...
33+
def dispatch_return(self, frame: FrameType, arg: Any) -> TraceFunction: ...
34+
def dispatch_exception(self, frame: FrameType, arg: ExcInfo) -> TraceFunction: ...
3635
def is_skipped_module(self, module_name: str) -> bool: ...
3736
def stop_here(self, frame: FrameType) -> bool: ...
3837
def break_here(self, frame: FrameType) -> bool: ...

stdlib/concurrent/futures/_base.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class Future(Generic[_T]):
4949
def cancelled(self) -> bool: ...
5050
def running(self) -> bool: ...
5151
def done(self) -> bool: ...
52-
def add_done_callback(self, fn: Callable[[Future[_T]], Any]) -> None: ...
52+
def add_done_callback(self, fn: Callable[[Future[_T]], object]) -> None: ...
5353
def result(self, timeout: float | None = ...) -> _T: ...
5454
def set_running_or_notify_cancel(self) -> bool: ...
5555
def set_result(self, result: _T) -> None: ...

stdlib/concurrent/futures/process.pyi

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ from weakref import ref
1010

1111
from ._base import BrokenExecutor, Executor, Future
1212

13+
_T = TypeVar("_T")
14+
1315
_threads_wakeups: MutableMapping[Any, Any]
1416
_global_shutdown: bool
1517

@@ -40,14 +42,12 @@ class _ExceptionWithTraceback:
4042

4143
def _rebuild_exc(exc: Exception, tb: str) -> Exception: ...
4244

43-
_S = TypeVar("_S")
44-
45-
class _WorkItem(Generic[_S]):
46-
future: Future[_S]
47-
fn: Callable[..., _S]
45+
class _WorkItem(Generic[_T]):
46+
future: Future[_T]
47+
fn: Callable[..., _T]
4848
args: Iterable[Any]
4949
kwargs: Mapping[str, Any]
50-
def __init__(self, future: Future[_S], fn: Callable[..., _S], args: Iterable[Any], kwargs: Mapping[str, Any]) -> None: ...
50+
def __init__(self, future: Future[_T], fn: Callable[..., _T], args: Iterable[Any], kwargs: Mapping[str, Any]) -> None: ...
5151

5252
class _ResultItem:
5353
work_id: int
@@ -90,7 +90,7 @@ class _SafeQueue(Queue[Future[Any]]):
9090
def _on_queue_feeder_error(self, e: Exception, obj: _CallItem) -> None: ...
9191

9292
def _get_chunks(*iterables: Any, chunksize: int) -> Generator[tuple[Any, ...], None, None]: ...
93-
def _process_chunk(fn: Callable[..., Any], chunk: tuple[Any, None, None]) -> Generator[Any, None, None]: ...
93+
def _process_chunk(fn: Callable[..., _T], chunk: Iterable[tuple[Any, ...]]) -> list[_T]: ...
9494

9595
if sys.version_info >= (3, 11):
9696
def _sendback_result(

stdlib/distutils/cmd.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Command:
2525
def run_command(self, command: str) -> None: ...
2626
def get_sub_commands(self) -> list[str]: ...
2727
def warn(self, msg: str) -> None: ...
28-
def execute(self, func: Callable[..., Any], args: Iterable[Any], msg: str | None = ..., level: int = ...) -> None: ...
28+
def execute(self, func: Callable[..., object], args: Iterable[Any], msg: str | None = ..., level: int = ...) -> None: ...
2929
def mkpath(self, name: str, mode: int = ...) -> None: ...
3030
def copy_file(
3131
self,
@@ -60,7 +60,7 @@ class Command:
6060
self,
6161
infiles: str | list[str] | tuple[str, ...],
6262
outfile: str,
63-
func: Callable[..., Any],
63+
func: Callable[..., object],
6464
args: list[Any],
6565
exec_msg: str | None = ...,
6666
skip_msg: str | None = ...,

stdlib/doctest.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class DocTestFinder:
126126
extraglobs: dict[str, Any] | None = ...,
127127
) -> list[DocTest]: ...
128128

129-
_Out: TypeAlias = Callable[[str], Any]
129+
_Out: TypeAlias = Callable[[str], object]
130130

131131
class DocTestRunner:
132132
DIVIDER: str
@@ -201,8 +201,8 @@ class DocTestCase(unittest.TestCase):
201201
self,
202202
test: DocTest,
203203
optionflags: int = ...,
204-
setUp: Callable[[DocTest], Any] | None = ...,
205-
tearDown: Callable[[DocTest], Any] | None = ...,
204+
setUp: Callable[[DocTest], object] | None = ...,
205+
tearDown: Callable[[DocTest], object] | None = ...,
206206
checker: OutputChecker | None = ...,
207207
) -> None: ...
208208
def setUp(self) -> None: ...

stdlib/ftplib.pyi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,22 +90,22 @@ class FTP:
9090
def ntransfercmd(self, cmd: str, rest: int | str | None = ...) -> tuple[socket, int]: ...
9191
def transfercmd(self, cmd: str, rest: int | str | None = ...) -> socket: ...
9292
def retrbinary(
93-
self, cmd: str, callback: Callable[[bytes], Any], blocksize: int = ..., rest: int | str | None = ...
93+
self, cmd: str, callback: Callable[[bytes], object], blocksize: int = ..., rest: int | str | None = ...
9494
) -> str: ...
9595
def storbinary(
9696
self,
9797
cmd: str,
9898
fp: SupportsRead[bytes],
9999
blocksize: int = ...,
100-
callback: Callable[[bytes], Any] | None = ...,
100+
callback: Callable[[bytes], object] | None = ...,
101101
rest: int | str | None = ...,
102102
) -> str: ...
103-
def retrlines(self, cmd: str, callback: Callable[[str], Any] | None = ...) -> str: ...
104-
def storlines(self, cmd: str, fp: SupportsReadline[bytes], callback: Callable[[bytes], Any] | None = ...) -> str: ...
103+
def retrlines(self, cmd: str, callback: Callable[[str], object] | None = ...) -> str: ...
104+
def storlines(self, cmd: str, fp: SupportsReadline[bytes], callback: Callable[[bytes], object] | None = ...) -> str: ...
105105
def acct(self, password: str) -> str: ...
106106
def nlst(self, *args: str) -> list[str]: ...
107107
# Technically only the last arg can be a Callable but ...
108-
def dir(self, *args: str | Callable[[str], None]) -> None: ...
108+
def dir(self, *args: str | Callable[[str], object]) -> None: ...
109109
def mlsd(self, path: str = ..., facts: Iterable[str] = ...) -> Iterator[tuple[str, dict[str, str]]]: ...
110110
def rename(self, fromname: str, toname: str) -> str: ...
111111
def delete(self, filename: str) -> str: ...

0 commit comments

Comments
 (0)