Skip to content

Commit a3a17b0

Browse files
authored
Add stubs for watchpoints (#13248)
1 parent 6f98c59 commit a3a17b0

9 files changed

+171
-0
lines changed

pyrightconfig.stricter.json

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
"stubs/tqdm",
9696
"stubs/ttkthemes",
9797
"stubs/vobject",
98+
"stubs/watchpoints",
9899
"stubs/workalendar",
99100
"stubs/wurlitzer",
100101
],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
watchpoints.all

stubs/watchpoints/METADATA.toml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
version = "0.2.5"
2+
upstream_repository = "https://github.com/gaogaotiantian/watchpoints"
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from collections.abc import Callable
2+
from typing import Final
3+
from typing_extensions import LiteralString, Unpack
4+
5+
from .watch import Watch
6+
7+
__version__: Final[LiteralString]
8+
9+
watch: Watch
10+
unwatch: Final[Callable[[Unpack[tuple[object, ...]]], None]]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import ast
2+
3+
def ast_parse_node(node: ast.expr) -> ast.Module: ...
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import ast
2+
from collections.abc import Iterable
3+
from types import FrameType
4+
5+
def getline(frame: FrameType) -> str: ...
6+
def getargnodes(frame: FrameType) -> Iterable[tuple[ast.expr, str]]: ...
+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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: ...
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import ast
2+
from collections.abc import Callable, Iterable
3+
from types import FrameType
4+
from typing import Any, Literal, TypeVar
5+
from typing_extensions import TypeAlias
6+
7+
from .watch_print import WatchPrint
8+
9+
_T = TypeVar("_T")
10+
_TrackKind: TypeAlias = Literal["object", "variable"] | list[Literal["object", "variable"]]
11+
12+
class WatchElement:
13+
# User-defined callbacks passed to `__init__` set as instance variables have arguments of type `Any` to be
14+
# compatible with more precisely-annotated signatures. These callbacks are passed from `watchpoints.watch.Watch`.
15+
16+
alias: str | None
17+
attr: str | None
18+
cmp: Callable[[Any, Any], bool] | None
19+
copy: Callable[[Any], object] | None # User-defined copy callback
20+
default_alias: str | None
21+
deepcopy: bool
22+
exist: bool
23+
frame: FrameType
24+
localvar: str | None
25+
obj: Any
26+
parent: Any
27+
prev_obj: Any
28+
prev_obj_repr: str
29+
subscr: Any
30+
watch_print: WatchPrint
31+
when: Callable[[Any], bool] | None
32+
33+
def __init__(
34+
self,
35+
frame: FrameType,
36+
node: ast.expr,
37+
*,
38+
alias: str | None = ...,
39+
callback: Callable[[FrameType, WatchElement, tuple[str, str, int | None]], None] | None = ...,
40+
cmp: Callable[[Any, Any], bool] | None = ..., # User-defined comparison callback
41+
copy: Callable[[_T], _T] | None = ...,
42+
deepcopy: bool = False,
43+
default_alias: str | None = ...,
44+
track: _TrackKind = ...,
45+
watch_print: WatchPrint = ...,
46+
when: Callable[[Any], bool] | None = ..., # User-defined callback for conditional watchpoints
47+
) -> None: ...
48+
def belong_to(self, lst: Iterable[object]) -> bool: ...
49+
def changed(self, frame: FrameType) -> tuple[bool, bool]: ...
50+
def obj_changed(self, other: object) -> bool: ...
51+
def same(self, other: object) -> bool: ...
52+
@property
53+
def track(self) -> _TrackKind: ...
54+
@track.setter
55+
def track(self, val: _TrackKind) -> None: ...
56+
def update(self) -> None: ...
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from _typeshed import SupportsWrite
2+
from collections.abc import Callable
3+
from types import FrameType
4+
from typing import Any
5+
6+
from .watch_element import WatchElement
7+
8+
class WatchPrint:
9+
# User-defined callbacks passed to `__init__` set as instance variables have arguments of type `Any` to be
10+
# compatible with more precisely-annotated signatures. These callbacks are passed from `watchpoints.watch.Watch`.
11+
12+
custom_printer: Callable[[Any], None] | None
13+
file: str | SupportsWrite[str] | None
14+
stack_limit: int | None
15+
16+
def __init__(
17+
self,
18+
file: str | SupportsWrite[str] | None = ...,
19+
stack_limit: int | None = ...,
20+
custom_printer: Callable[[Any], None] | None = ..., # User-defined printing callback
21+
) -> None: ...
22+
def __call__(self, frame: FrameType, elem: WatchElement, exec_info: tuple[str, str, int | None]) -> None: ...
23+
def getsourceline(self, exec_info: tuple[str, str, int | None]) -> str: ...
24+
def printer(self, obj: object) -> None: ...

0 commit comments

Comments
 (0)