|
| 1 | +import threading |
| 2 | +from _typeshed import SupportsWrite, TraceFunction |
| 3 | +from collections.abc import Callable |
| 4 | +from pdb import Pdb |
| 5 | +from types import FrameType |
| 6 | +from typing import Any, Literal, Protocol, TypeVar |
| 7 | +from typing_extensions import TypeAlias |
| 8 | + |
| 9 | +from .watch_element import WatchElement |
| 10 | + |
| 11 | +_T = TypeVar("_T") |
| 12 | + |
| 13 | +# Alias used for fields that must always be valid identifiers |
| 14 | +# A string `x` counts as a valid identifier if both the following are True |
| 15 | +# (1) `x.isidentifier()` evaluates to `True` |
| 16 | +# (2) `keyword.iskeyword(x)` evaluates to `False` |
| 17 | +_Identifier: TypeAlias = str |
| 18 | + |
| 19 | +class Watch: |
| 20 | + # User-defined callbacks passed to `__call__()` or `config()` set as instance variables have arguments of type `Any` to be |
| 21 | + # compatible with more precisely-annotated signatures. |
| 22 | + |
| 23 | + custom_printer: Callable[[Any], None] | None |
| 24 | + enable: bool |
| 25 | + file: str | SupportsWrite[str] | None |
| 26 | + pdb: Pdb | None |
| 27 | + pdb_enable: bool |
| 28 | + set_lock: threading.Lock |
| 29 | + stack_limit: int | None |
| 30 | + tracefunc_lock: threading.Lock |
| 31 | + tracefunc_stack: list[TraceFunction | None] |
| 32 | + watch_list: list[WatchElement] |
| 33 | + |
| 34 | + def __init__(self) -> None: ... |
| 35 | + def __call__( |
| 36 | + self, |
| 37 | + *args: object, |
| 38 | + alias: str = ..., |
| 39 | + callback: Callable[[FrameType, WatchElement, tuple[str, str, int | None]], None] = ..., |
| 40 | + cmp: Callable[[Any, Any], bool] = ..., # User-defined comparison callback; compares 2 arguments of any type |
| 41 | + copy: Callable[[_T], _T] = ..., |
| 42 | + # User-defined printing callback; writes a string representation of any object to a stream |
| 43 | + custom_printer: Callable[[Any], None] = ..., |
| 44 | + deepcopy: bool = False, |
| 45 | + file: str | SupportsWrite[str] = ..., |
| 46 | + stack_limit: int | None = 5, |
| 47 | + track: Literal["object", "variable"] = ..., |
| 48 | + when: Callable[[Any], bool] = ..., # User-defined callback for conditional watchpoints |
| 49 | + ) -> None: ... |
| 50 | + def config( |
| 51 | + self, |
| 52 | + *, |
| 53 | + callback: Callable[[FrameType, WatchElement, tuple[str, str, int | None]], None] = ..., |
| 54 | + pdb: Literal[True] = ..., |
| 55 | + file: str | SupportsWrite[str] = ..., |
| 56 | + stack_limit: int | None = 5, |
| 57 | + custom_printer: Callable[[Any], None] = ..., # User-defined printing callback |
| 58 | + ) -> None: ... |
| 59 | + def install(self, func: _Identifier = "watch") -> None: ... |
| 60 | + def restore(self) -> None: ... |
| 61 | + def start_trace(self, frame: FrameType) -> None: ... |
| 62 | + def stop_trace(self, frame: FrameType) -> None: ... |
| 63 | + def tracefunc(self, frame: FrameType, event: str, arg: object) -> _TraceFunc: ... |
| 64 | + def uninstall(self, func: _Identifier = "watch") -> None: ... |
| 65 | + def unwatch(self, *args: object) -> None: ... |
| 66 | + |
| 67 | +class _TraceFunc(Protocol): |
| 68 | + def __call__(self, frame: FrameType, event: str, arg: object) -> _TraceFunc: ... |
0 commit comments