Skip to content

Export public types and ship py.typed marker - #147

Merged
Leggin merged 1 commit into
mainfrom
export-public-types
Oct 23, 2026
Merged

Leggin merged 1 commit into
mainfrom
export-public-types

Conversation

@Leggin

@Leggin Leggin commented Oct 23, 2026 •

Copy link
Copy Markdown
Owner

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.typed marker (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 becomes Any.
  • Plain runtime imports instead of if typing.TYPE_CHECKING:. With the guard, from dirigera import Light passes mypy but raises ImportError at runtime. hub.py already imports every device module, so this adds no import cost.
  • __all__. Under mypy --strict / pyright, a bare from .x import Y in __init__.py is 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.
  • Built the wheel, installed it in a clean venv and ran mypy --strict on a consumer script: from dirigera import Hub, Light resolves to the real types (dirigera.devices.light.Light, etc.) with no errors, and the same import works at runtime.

Closes #146.

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
Leggin force-pushed the export-public-types branch from 0d75b5c to d4b7432 Compare October 23, 2026 15:30
@Leggin
Leggin merged commit 3c55130 into main Oct 23, 2026
8 checks passed
@Popaulol

Copy link
Copy Markdown
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

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.

2 participants