Skip to content

src/dirigera/__init__.py: Add imports at type check time - #146

Closed
Popaulol wants to merge 1 commit into
Leggin:mainfrom
Popaulol:main
Closed

Popaulol wants to merge 1 commit into
Leggin:mainfrom
Popaulol:main

Conversation

@Popaulol

Copy link
Copy Markdown
Contributor

when users are using the library, they may also want to type-annotate their own code like we do internally, so we should expose the Types they might use for type checking, even if we don't want to expose them for public use.

the typing.TYPE_CHECKING ensures that the users can't actually access the classes at runtime.

Although some of these classes, particularly in devices.scene could also be of some legitimate use to some users, for example to create new scenes from their Code.

when users are using the library, they may also want to type-annotate their own code like we do internally,
so we should expose the Types they might use for type checking,
even if we don't want to expose them for public use.
@Leggin

Leggin commented Oct 23, 2026

Copy link
Copy Markdown
Owner

Thanks a lot for this, @Popaulol! Exposing the types from the package root is a great idea.

While testing it against an installed wheel we found the types didn't reach users yet: the package had no py.typed marker (so type checkers treated it as untyped), and names imported only under TYPE_CHECKING make from dirigera import Light pass mypy but fail at runtime with ImportError.

#147 builds on your change: it exports the same classes with regular imports listed in __all__ and ships py.typed. You're credited as co-author on the commit. Closing this one in favour of #147, and it will go out in the next release.

@Leggin Leggin closed this Oct 23, 2026
Leggin added a commit that referenced this pull request Oct 23, 2026
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 added a commit that referenced this pull request Oct 23, 2026
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>
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