Skip to content
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

Improve sync_wrapper's definition so that we get better typing #2178

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from

Conversation

Ten0
Copy link

@Ten0 Ten0 commented Dec 14, 2024

Before, calling functions such as self.get_state or self.turn_on with anything else but the required type (in these two cases, str) would not lead to a type error, but rather to a runtime error long down the chain.

This now properly fails to typecheck.

Argument of type "whatever" cannot be assigned to parameter "entity_id" of type "str"

Ten0 added 6 commits December 14, 2024 03:03
Because otherwise the type will enforce that the caller checks which variant it is, which is too verbose.

Ultimately this probably means that we shouldn't overload methods like this, but instead should have a separate interface for the non-async case where all methods are explicitly non-async, so that we can remove those annotations from the async ones and then the typer can help us to not forget "await".
This would prevent from calling them with e.g. `str | None` with the previous changes.
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.

1 participant