Skip to content

Mill typing#49712

Closed
Danielhiversen wants to merge 5 commits into
devfrom
mill_typping
Closed

Mill typing#49712
Danielhiversen wants to merge 5 commits into
devfrom
mill_typping

Conversation

@Danielhiversen
Copy link
Copy Markdown
Member

Breaking change

Proposed change

Improve Mill typing

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example entry for configuration.yaml:

# Example configuration.yaml

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

To help with the load of incoming pull requests:

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

@KapJI KapJI Apr 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of scope for this PR, but should we enable warn_return_any in MyPy?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually it should be already enabled. I'll check why it doesn't work in this case.

Copy link
Copy Markdown
Member

@KapJI KapJI Apr 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shows a warning when returning a value with type Any from a function declared with a non- Any return 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.

Comment thread homeassistant/components/mill/climate.py Outdated

@property
def available(self):
def available(self) -> Any:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def available(self) -> Any:
def available(self) -> bool:

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would require the mill library to support typing?

Copy link
Copy Markdown
Member

@KapJI KapJI Apr 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. It will also need to export py.typed marker: PEP 561.


@property
def unique_id(self):
def unique_id(self) -> Any:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def unique_id(self) -> Any:
def unique_id(self) -> str:


@property
def name(self):
def name(self) -> Any:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def name(self) -> Any:
def name(self) -> str:


@property
def target_temperature(self):
def target_temperature(self) -> Any:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of scope for this PR, but should we enable warn_return_any in MyPy?

@Danielhiversen
Copy link
Copy Markdown
Member Author

Is it required that the underlying libary (pyMill in this case) supports typing first?

@KapJI
Copy link
Copy Markdown
Member

KapJI commented Apr 26, 2021

IMO, it makes a lot of sense. Annotating methods with Any although passes strict mypy checks formally, but doesn't really provide the value strict checks are intended to do.

In general Any should be avoided unless really necessary.

Co-authored-by: Franck Nijhof <git@frenck.dev>
Signed-off-by: Daniel Hjelseth Høyer <github@dahoiv.net>
@github-actions github-actions Bot locked and limited conversation to collaborators May 23, 2021
@Danielhiversen Danielhiversen deleted the mill_typping branch September 26, 2021 08:09
@Danielhiversen Danielhiversen restored the mill_typping branch September 26, 2021 08:09
@Danielhiversen Danielhiversen deleted the mill_typping branch January 19, 2022 14:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants