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 Type Hints and py.typed Support for zenpy #671

Open
jackton1 opened this issue Dec 3, 2024 · 4 comments
Open

Add Type Hints and py.typed Support for zenpy #671

jackton1 opened this issue Dec 3, 2024 · 4 comments

Comments

@jackton1
Copy link

jackton1 commented Dec 3, 2024

Hi,

Thank you for creating and maintaining the zenpy library! It’s been incredibly useful for our projects.

I’d like to request adding type hints and py.typed support to the library to improve compatibility with static type checkers like mypy. Currently, when using zenpy with mypy, we encounter the following errors:

error: Skipping analyzing "zenpy.lib.api_objects": module is installed, but missing library stubs or py.typed marker  [import-untyped]
error: Skipping analyzing "zenpy.lib.exception": module is installed, but missing library stubs or py.typed marker  [import-untyped]

These errors occur because zenpy does not include type annotations or a py.typed marker file. Adding type hints would greatly enhance the developer experience by enabling type checking and better IDE support.

Suggested Solution:

  1. Add inline type annotations to the codebase using PEP 484.
  2. Include a py.typed marker file in the package to indicate that it supports type hints (PEP 561).

Benefits:

  • Improved compatibility with mypy and other static type checkers.
  • Enhanced IDE features like autocompletion and type inference.
  • Easier debugging and reduced runtime errors for users.

If adding type hints directly to the library is not feasible, an alternative could be to provide type stubs (.pyi files) in a separate package or include them in the repository.

Thank you for considering this request, and please let me know if there’s anything I can do to help with this effort!

@cryptomail
Copy link
Collaborator

I'm still thinking about this :)
I do like types but this would be fairly disruptive, as the library is non trivial in size and complexity.
I'll have a read on the PEP, but understand types are nice to have and it's my personal opinion that safety and efficacy are derived not from types, but instead good developer practices and hygiene haha :)
I hear you on enhancing the ease of development though with editors etc.
I personally use intelliJ, and it seems to hint and parse things OK-ish.
Of course starting out with types would have made this whole thing moot, but we are where we are.

@rodigu
Copy link

rodigu commented Dec 10, 2024

Type hints would be nice.

@cryptomail
Copy link
Collaborator

Haha just got to the Juicy part, sorry for thought stream in Issues...but this made me chuckle a little bit :)

"Python will remain a dynamically typed language, and the authors have no desire to ever make type hints mandatory, even by convention."

That is not stopping my curiosity :P Continuing reading :P

@cryptomail
Copy link
Collaborator

someone showed me the easy button: https://github.com/Instagram/MonkeyType
I'm wondering if I can get the aspects to hook into and run during a test run.......

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

No branches or pull requests

3 participants