-
-
Notifications
You must be signed in to change notification settings - Fork 2.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
Fix inference when class and instance match protocol #18587
Conversation
This comment has been minimized.
This comment has been minimized.
OK, so the starlette thing used to work because of a chain of truly bizarre "coincidences" (bugs compensating bugs). It will take a while to unwind all this. This PR exposed a whole can of worms. |
This comment has been minimized.
This comment has been minimized.
Diff from mypy_primer, showing the effect of this PR on open source code: pandas (https://github.com/pandas-dev/pandas)
+ pandas/core/arrays/categorical.py:2939: error: Unused "type: ignore" comment [unused-ignore]
django-stubs (https://github.com/typeddjango/django-stubs): 1.42x faster (55.6s -> 39.3s in a single noisy sample)
steam.py (https://github.com/Gobot1234/steam.py)
- steam/ext/commands/help.py:36: error: Argument 1 to "__init__" of "Command" has incompatible type "Callable[[Context[Any], DefaultNamedArg(str | None, 'content')], Coroutine[Any, Any, None]]"; expected "Callable[[None, Context[Any], VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]] | Callable[[Context[Any], VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]" [arg-type]
- steam/ext/commands/bot.py:203: error: Signature of "dispatch" incompatible with supertype "Client" [override]
- steam/ext/commands/bot.py:203: note: Superclass:
- steam/ext/commands/bot.py:203: note: def dispatch(self, str, /, *args: Any, **kwargs: Any) -> None
- steam/ext/commands/bot.py:203: note: Subclass:
- steam/ext/commands/bot.py:203: note: def dispatch(self, event: str, *args: Any, **kwargs: Any) -> None
core (https://github.com/home-assistant/core)
+ homeassistant/components/sensor/const.py:593: error: Dict entry 39 has incompatible type "SensorDeviceClass": "set[UnitOfSpeed | UnitOfVolumetricFlux]"; expected "SensorDeviceClass": "set[type[StrEnum] | str | None]" [dict-item]
+ homeassistant/components/number/const.py:497: error: Dict entry 39 has incompatible type "NumberDeviceClass": "set[UnitOfSpeed | UnitOfVolumetricFlux]"; expected "NumberDeviceClass": "set[type[StrEnum] | str | None]" [dict-item]
+ homeassistant/helpers/entity_registry.py:90: error: Unused "type: ignore" comment [unused-ignore]
|
OK, |
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, nice to see a fix to a highly voted issue! Looks good.
These changes all make sense, thank you for fixing several chained bugs :-) |
Fixes #14688
The bug resulted from (accidentally) inferring against
Iterable
for both instance and class object. While working on this I noticed there are also couple flaws in direction handling in constrain inference, namely:Type[X]
I also (conservatively) fix some unrelated issues uncovered by the fix (to avoid fallout):
Parameters
could lead to meaningless results in case of incompatible arg kinds