Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/watchpoints #13248

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Feat/watchpoints #13248

wants to merge 6 commits into from

Conversation

bzoracler
Copy link
Contributor

This is a complete set of stubs for the watchpoints package (GitHub: https://github.com/gaogaotiantian/watchpoints).

Even though it seems like activity is low, it still gets ~800 downloads a week, and its lowish numbers are due to it being a debugging tool rather than a dependency library.

Its stated Python support ranges (3.6-3.10) are modest - I've run the tests locally on Python 3.13-dev and they pass without any modifications.

The intended API and types were inferred through the implementation and the README.

This comment has been minimized.

@bzoracler
Copy link
Contributor Author

bzoracler commented Dec 14, 2024

pyright error seems like a bug - reported at microsoft/pyright#9584 Not a bug

This comment has been minimized.

This comment has been minimized.

Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

_Identifier: TypeAlias = str

class Watch:
custom_printer: Callable[[Any], None] | None
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Several callback types this package have Any as argument type(s), which are assigned with user-defined callbacks. I avoided using object here to be compatible with user-defined callbacks, which may annotate the parameters with more precise types.

  • Printer callbacks: accepts any object and writes to a stream
  • Compare (cmp) callbacks: Accepts any 2 objects and compare their equality
  • copy: Makes a copy of any object
  • when callbacks: Inspect/trace/watch an object when a condition is fulfilled; takes any object and outputs a bool.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, but please add a comment to the code explaining this.

@bzoracler bzoracler marked this pull request as ready for review December 14, 2024 20:39

__version__: Final[LiteralString]

all: Final[list[Literal["watch", "unwatch"]]]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is a typo for __all__, worth reporting as a bug to the runtime package.

from types import FrameType

def getline(frame: FrameType) -> str: ...
def getargnodes(frame: FrameType) -> zip[tuple[ast.expr, str]]: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def getargnodes(frame: FrameType) -> zip[tuple[ast.expr, str]]: ...
def getargnodes(frame: FrameType) -> Iterable[tuple[ast.expr, str]]: ...

It does return a zip object at runtime, but that's a bit too much of an implementation detail for my taste.

def __init__(self) -> None: ...
def __call__(
self,
*args: object,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like these are unused, consider using _typeshed.Unused.

_Identifier: TypeAlias = str

class Watch:
custom_printer: Callable[[Any], None] | None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, but please add a comment to the code explaining this.

def __call__(
self,
*args: object,
alias: str = ...,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one and most of the others support None, since the runtime does kwargs.get("alias", None). Add None to the allowed type of these parameters.

deepcopy: bool = False,
file: str | SupportsWrite[str] = ...,
stack_limit: int | None = 5,
track: Literal["object", "variable"] = ...,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
track: Literal["object", "variable"] = ...,
track: list[Literal["object", "variable"]] = ...,

Or does it also support other kinds of Sequences?

def unwatch(self, *args: object) -> None: ...

class _TraceFunc(Protocol):
def __call__(self, frame: FrameType, event: str, arg: object) -> _TraceFunc: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these parameters be positional-only?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants