Repository navigation
Export public types and ship py.typed marker - #147
Merged
Merged
Conversation
Re-export the device, attribute, enum and scene classes from the package root and list them in __all__, so users can write `from dirigera import Light` and strict type checkers treat the names as exported. Imports are plain runtime imports rather than TYPE_CHECKING-only, so the same import works when the code runs. Add a py.typed marker (and include it as package data) so type checkers use the library's annotations instead of treating it as untyped. Based on the idea and import list from #146 by @Popaulol. Co-authored-by: Strawberry <56090021+Popaulol@users.noreply.github.com>
Leggin
force-pushed
the
export-public-types
branch
from
October 23, 2026 15:30
0d75b5c to
d4b7432
Compare
Contributor
|
Thank you for implementing it in this way and building on my commit. tbh i had hacked together my solution to make it work with my local typechecking setup and hadn't tested it on release build, just with having a local clone of the dirigera repo in the same directory |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Lets users import the library's types from the package root (
from dirigera import Light) and have type checkers pick them up.Idea and import list from #146 by @Popaulol, thank you! This builds on it with three adjustments that we found were needed for the types to actually propagate to users:
py.typedmarker (plus[tool.setuptools.package-data]so it ships in the wheel with any setuptools version). Without it, mypy/pyright treat the installed package as untyped and everything becomesAny.if typing.TYPE_CHECKING:. With the guard,from dirigera import Lightpasses mypy but raisesImportErrorat runtime.hub.pyalready imports every device module, so this adds no import cost.__all__. Undermypy --strict/ pyright, a barefrom .x import Yin__init__.pyis not treated as a re-export ("Module "dirigera" does not explicitly export attribute ...").Also adds a small test that every name in
__all__exists.Verification
mypy .,pytest(86 passed) and pylint (score unchanged vs main) pass locally.mypy --stricton a consumer script:from dirigera import Hub, Lightresolves to the real types (dirigera.devices.light.Light, etc.) with no errors, and the same import works at runtime.Closes #146.