Mill typing#49712
Conversation
Signed-off-by: Daniel Hjelseth Høyer <github@dahoiv.net>
Signed-off-by: Daniel Hjelseth Høyer <github@dahoiv.net>
Signed-off-by: Daniel Hjelseth Høyer <github@dahoiv.net>
| from collections.abc import Sequence | ||
| from typing import Any, Callable | ||
|
|
||
| from mill import Heater, Mill |
There was a problem hiding this comment.
You're the author of mill library, why not you add type hints there first? It looks pretty small. This will allow to get rid of most Any here.
There was a problem hiding this comment.
Out of scope for this PR, but should we enable warn_return_any in MyPy?
There was a problem hiding this comment.
Actually it should be already enabled. I'll check why it doesn't work in this case.
There was a problem hiding this comment.
Shows a warning when returning a value with type
Anyfrom a function declared with a non-Anyreturn type.
https://mypy.readthedocs.io/en/stable/config_file.html#confval-warn_return_any
Here underlying library is untyped, therefore all fields have Any type.
Basically this prevents from specifying type other than Any for return type. I think underlying library should be updated first.
|
|
||
| @property | ||
| def available(self): | ||
| def available(self) -> Any: |
There was a problem hiding this comment.
| def available(self) -> Any: | |
| def available(self) -> bool: |
There was a problem hiding this comment.
Would require the mill library to support typing?
There was a problem hiding this comment.
Yes. It will also need to export py.typed marker: PEP 561.
|
|
||
| @property | ||
| def unique_id(self): | ||
| def unique_id(self) -> Any: |
There was a problem hiding this comment.
| def unique_id(self) -> Any: | |
| def unique_id(self) -> str: |
|
|
||
| @property | ||
| def name(self): | ||
| def name(self) -> Any: |
There was a problem hiding this comment.
| def name(self) -> Any: | |
| def name(self) -> str: |
|
|
||
| @property | ||
| def target_temperature(self): | ||
| def target_temperature(self) -> Any: |
There was a problem hiding this comment.
| def target_temperature(self) -> Any: | |
| def target_temperature(self) -> float: |
| from collections.abc import Sequence | ||
| from typing import Any, Callable | ||
|
|
||
| from mill import Heater, Mill |
There was a problem hiding this comment.
Out of scope for this PR, but should we enable warn_return_any in MyPy?
|
Is it required that the underlying libary (pyMill in this case) supports typing first? |
|
IMO, it makes a lot of sense. Annotating methods with In general |
Co-authored-by: Franck Nijhof <git@frenck.dev>
Signed-off-by: Daniel Hjelseth Høyer <github@dahoiv.net>
Breaking change
Proposed change
Improve Mill typing
Type of change
Example entry for
configuration.yaml:# Example configuration.yamlAdditional information
Checklist
black --fast homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all..coveragerc.The integration reached or maintains the following Integration Quality Scale:
To help with the load of incoming pull requests: