-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
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 dispatcher typing #106872
Improve dispatcher typing #106872
Conversation
Hey there @emontnemery, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
Hey there @home-assistant/cloud, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
The idea sounds ok, but we can't use it if mypy gives an error. |
The issue with mypy is that it can't detect error due to incorrect typing yet, i.e. a Opened an issue for mypy: python/mypy#16739 -- |
Isn't that a false negative? |
Yeah, I thought that I might have mixed them up 😅 |
It's good that the mypy error isn't in the way although it'll give a somewhat false sense of comfort. I'm positive to the change. Let's hear what others think. |
Opened a PR for Mypy. Hope it makes it in time for the next release. python/mypy#16759
👍🏻 |
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.
Proposed change
An idea to improve the dispatcher typing, in particular
async_dispatcher_connect
andasync_dispatcher_send
.At the moment there is no automated check to see if either a compatible callable is passed to
async_dispatcher_connect
orasync_dispatcher_send
is called with the right arguments.This PR adds a new generic type
SignalType
to enable mypy to find these issues and Pylance to provide better intellisense support.With the updated typing the last two calls will result in type errors.
Pylance can already detect both whereas mypy seems have a bug with the second one, unfortunately.
--
My first idea was to make
SignalType
inherit fromstr
to be able to use them interchangeably. Unfortunately, that meant the type checkers would revert back to thestr
overload if the arguments didn't match defeating the whole purpose of this change. I've added custom__hash__
and__eq__
methods forSignalType
to be compatible with string dict keys.Type of change
Additional information
Checklist
ruff format 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: