-
-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
Add override decorators to sensor #94998
Conversation
Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
Marked it as draft for a moment, will get back to this. ../Frenck |
@cdce8p Discussed this a bit, and wondering if this can be enforced? Like for example, if an integration has strict typing enabled within Home Assistant, can we error with MyPy an |
Not yet. That is the strict mode suggested in the PEP. Mypy doesn't implement it yet. It looks fairly easy to add which is why I already had the https://peps.python.org/pep-0698/#strict-enforcement-per-project |
Right, so the reason for asking is that we think it might be confusion/adding a level of complexity for newer contributors, ending up slapping it onto everything or nothing at all. Therefore, it would be nice if we could check and enforce it has been applied and correctly applied in case strict mode is enabled for the specific integration. Only that way we can guarantee it is correctly done. In the far future we might change it when this becomes more common of course. |
FYI The strict mode will be part of the next mypy release. My PR was just merged. python/mypy#15512 |
Now possible with mypy |
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.
Thanks, @cdce8p 👍
../Frenck
Proposed change
Followup to the recent mypy upgrade: #94987
This PR adds the first
override
decorators. Is that something we want to do? Although the performance impact should minimal, adding it to so many methods might still be noticeable - haven't checked that. Basically it could be added to each integration / platform multiple times.Mypy doesn't yet implement the strict mode, which would require the decorator if a method overrides an implementation in a base class, suggested in the PEP. However, we could start adding it now. FYI: For the strict mode, we would roughly need to add it 4.800 times.
https://docs.python.org/3.12/library/typing.html#typing.override
/CC: @frenck
Type of change
Additional 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
.To help with the load of incoming pull requests: