[python-package] declare the use of inline type hints #5709
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Contributes to #3756.
Contributes to #3867.
This PR proposes updating the Python package to declare that inline type annotations are used.
Typing :: Typed
py.typed
fileWhy add the
Typing :: Typed
trove classifier?This classifier helps researchers and others summarizing PyPI's contents to identify packages that export type annotations.
See the discussion in pypi/warehouse#4348.
There are 5200+ packages on PyPI using this classifier: https://pypi.org/search/?c=Typing+%3A%3A+Typed.
Why add a
py.typed
file?As described in PEP 561 (link), including an empty file named
py.typed
tells tools likemypy
that a package's source code contains type annotations.That doesn't matter for
lightgbm
itself, but it's helpful for anyone writing code that depends onlightgbm
(e.g.optuna
,lightgbm-ray
, lots of other user code) and wanting to check that code withmypy
.Consider the following example. Given the following file...
Running
if you have
lightgbm < 4.0
installed from PyPI or frommaster
, you'll see the following error.But on this branch,
mypy
is able to check that code 😁