-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
Update mypy to a custom version #111258
Update mypy to a custom version #111258
Conversation
Result from a recent typeshed change -> better asyncio callback typing with Ts
501b27a
to
da42883
Compare
Have we considered switching to pyright? What would be the consequences of that? |
Technically it would be possible. However, likely quite a bit of work to get everything working as it is now. There is a lot of custom configuration especially around strict typing integrations. Personally, I use VSCode with Pylance / pright every day. I've even set Most notably in how pyright infers variables without annotations, the vast majority. Whereas mypy assumes the type to be the one of the first assignment, pyright is happy to add any additional ones as needed and combine them into a union. Maybe that's a preference thing but I prefer the way mypy handles that. I don't want to go around the whole codebase and just add type annotations to limit def f(some_val: bool) -> None:
x = 1
reveal_type(x)
if some_val:
x = ""
reveal_type(x) # mypy
test.py:3: note: Revealed type is "builtins.int"
test.py:5: error: Incompatible types in assignment (expression has type "str", variable has type "int") [assignment]
test.py:6: note: Revealed type is "builtins.int" # pyright
test.py:3:17 - information: Type of "x" is "Literal[1]"
test.py:6:17 - information: Type of "x" is "Literal['', 1]" -- -- |
Just to provide some more context regarding pyright. Did a run over the
Quite possible that a lot of these would go away fairly quickly but it isn't just plug and play. Update |
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.
We've discussed this in the core team and think it's ok. It's not great to not use upstream packages, but we think this is worth it in this case. 👍
Thanks!
Proposed change
Unfortunately, the mypy releases don't happen quite as regular as I would like. Usually that isn't a big issue, however this time the next version will include some features and bug fixes which are required for some major typing improvements.
The release itself was originally planned for the end of January, the release branch has even been cut already, unfortunately though there haven't been any updates over the last two weeks. It might happen early next week, or next month.
That's why I decided to create a project to build custom mypy version and upload them to PyPI. These can be used interchangeably which mypy itself, basically as a stop gap, until the next official release. The wheels are build using almost the same workflow, i.e. also compiled with mypyc. Only difference being that I chose not to compile / upload
musllinux
wheels. (If necessary, I can add that and push a new release.)https://pypi.org/project/mypy-dev/1.9.0b1/
https://github.com/cdce8p/mypy-dev/tree/1.9.0b1
https://github.com/cdce8p/mypy-dev/releases/tag/1.9.0b1
Release
1.9.0b1
tracks the current HEAD of therelease-1.9.0
branch python/mypy@155909a.Changes for Mypy 1.9.0 (incomplete)
DataUpdateCoordinator
.As long as the default isn't a TypeVarTuple or references another TypeVar.
=> This will also enable us to add generic typing to the
Event
class to get rid of sometype: ignores
aroundasync_listen
.Improve dispatcher typing #106872
Consider TypeVarTuple to be invariant python/mypy#16759
dict.__setitem__
with custom key types. Required foraiohttp.web.AppKey
andAdd HassDict implementation #103844
Fix missing type store for overloads python/mypy#16803
https://docs.aiohttp.org/en/stable/web_advanced.html#application-s-config
asyncio
callback types - anything with acallback
and only*args
, e.g.call_soon
. We could use something similar forasync_add_job
,async_add_hass_job
, ... .Plan for the future
As soon as there is an official release, I'll create a PR to use that one instead. Beyond that, if there is a similar situation in the future, it might make sense to temporarily switch again. So far, I don't expect that. This release is somewhat special as a lot of typing improvements are currently blocked.
Good to know
mypy --version
will print the development version as if mypy would have been installed from git. I.e. not1.9.0b1
but this insteadJust in case someone finds an issue and wants to open a bug report on the official mypy repo.
Refs
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: