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

Add py.typed and annotate most of the classes and methods #214

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

eternal-sorrow
Copy link
Contributor

@eternal-sorrow eternal-sorrow commented Feb 26, 2025

Supersedes #205, fixes #187.

I annotated types in most of the classes and methods instead of keeping it unannotated and just plugging mypy complaints with # type: ignore. With some notable exceptions:

  • I didn't touch synchronizer, because I don't understand how it works, looks like it has some undefined variables.
  • I didin't use any advanced trickery with types to make aio and non-aio classes compatible. I had to use # type: ignore here and there because of this, this could be avoided using some base class for Connection and aio.Connection, and also come common base class for Con and aio.Con instead of just inheriting one from the other.
  • I used some TypeVars for Con and replies. I tried to keep all of this compatible with python 3.9, so I didn't use any recent additions to typing system. This also caused some # type: ignores because advanced parameter annotations are not available. In my opinion, callbacks with no event argument should be deprecated though.

I also used a contravariant TypeVar to annotate the IpcBaseEvent argument for event handlers. This makes it possible for the users of this library to annotate their callbacks with actual event types they are expecting to receive (WindowEvent for example).

@eternal-sorrow eternal-sorrow changed the title Add py.typed and annotate most of the classes ant methods Add py.typed and annotate most of the classes and methods Feb 26, 2025
@eternal-sorrow eternal-sorrow marked this pull request as ready for review February 27, 2025 12:03
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.

Create PEP 561 compliant library stub for type checking
1 participant