-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add py.typed marker file for PEP 561 compatibility #2484
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
Conversation
This file signals to type checkers that the library provides inline type hints and should be type-checked, improving integration with tools like Mypy.
Not everything in pyTelegramBotAPI is typed. Will it hurt any cases? |
@coder2020official - I not actively use such type checkers, but I don't think it will make any bad. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.
No, It just makes the typed parts of your library work better with type-checking tools, without negatively impacting the untyped parts for users. |
Shouldn't we change pyproject.toml for that to work? |
You already included all telebot folder inside pyproject.toml. So, that is not required. |
Well, I am not sure overall |
Ok. You can check here: https://peps.python.org/pep-0561/ . It's also possible to be added by modifying the setup script like:
But just adding the file worked for me as well. |
Everything you left "for read" is left forever. I propose to apply )) |
Well if you propose applying, then do |
This file signals to type checkers that the library provides inline type hints and should be type-checked, improving integration with tools like Mypy.
Description
This pull request introduces a
py.typed
marker file to thetelebot
package, by PEP 561.Changes:
telebot/py.typed
file.Purpose & Benefits:
pyTelegramBotAPI
ships with inline type information and is intended to be type-checked.disallow_any_unimported
orcheck_untyped_defs
), as they will no longer incorrectly flagtelebot
imports as untyped.The existing Hatch build configuration (
[tool.hatch.build.targets.wheel] include = ["telebot/*"]
) inpyproject.toml
ensures this newpy.typed
file will be included in the distributed wheel.Describe your tests
Local Mypy Verification:
* Confirmed that without
telebot/py.typed
in my localpyTelegramBotAPI
installation, Mypy version [1.15.0] (withdisallow_any_unimported = true
inpyproject.toml
) reported errors fortelebot
imports (e.g.,error: Type of variable becomes "Any | None" due to an unfollowed import [no-any-unimported]
).* Manually added the
telebot/py.typed
file to my local installation ofpyTelegramBotAPI
.* Re-ran Mypy, and the previously mentioned errors related to
telebot
were resolved, indicating Mypy now correctly recognizes the library as typed.Python version: [3.11]
OS: [macOS Sonoma]
Checklist:
Additional Observation (Optional - For Maintainer Awareness):
During testing, I also ran
mypy telebot/
directly on the library's source code after addingpy.typed
. This revealed several internal type consistency errors reported by Mypy. While this PR solely focuses on adding thepy.typed
marker to enable proper type checking by consumers (which it successfully does), these internal findings might interest the maintainers for future type hinting refinement within the library itself. This PR does not attempt to address those internal errors.