-
Notifications
You must be signed in to change notification settings - Fork 68
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
Enable mypy #88
Enable mypy #88
Conversation
@@ -1,7 +1,9 @@ | |||
"""Models for Google Home""" | |||
|
|||
from __future__ import annotations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for using forward declared types in type hints: https://www.python.org/dev/peps/pep-0563/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmmm, my knowledge is quite limited on __future__
and annotations, so dont really follow what it's doing 🤔 It is postponing annotations to prevent from runtime executed annotations. But why? Do you understand showing annotations at runtime when function/variable is called is a problem? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically this allows you to use types before they're defined.
For example here it is:
def get_next_alarm(self) -> Optional[GoogleHomeAlarm]:
Otherwise you need to use string:
def get_next_alarm(self) -> Optional["GoogleHomeAlarm"]:
Should be enabled by default in Python 3.10.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uuu that't nice, thanks, i hope i get it a bit better now
Feel free to add type hints to more parts after you merge this 🙂 |
@leikoilja can you take a look? 🙂 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general looks really good to me! Thanks for making it! I have a few conceptual questions, but those are mostly around my limited understanding of a topic :) If you could help clearing those up, i'd be happy
[mypy-glocaltokens.*] | ||
ignore_missing_imports = True | ||
|
||
[mypy-homeassistant.*] | ||
ignore_missing_imports = True | ||
|
||
[mypy-voluptuous.*] | ||
ignore_missing_imports = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These packages don't distrubute typing information (don't have py.typed
marker) and mypy
will complain that it can't import these packages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, thank you!
Check glocaltokens
open PR, i think it's ready to go. I have added py.typed
as requested :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, with it we can remove glocaltokens
from here and type check its usages :)
Add it to
pre-commit
config.Unfortunately,
homeassistant
,voluptuous
andglocaltokens
don't distribute typing information.I'll try to enable it for
homeassistant
.@leikoilja can you enable this for
glocaltokens
? Should be one line insetup.py
.https://www.python.org/dev/peps/pep-0561/