-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Omit constraints referencing dict
if a conflicting TypedDict
constraint exists
#19225
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
base: master
Are you sure you want to change the base?
Omit constraints referencing dict
if a conflicting TypedDict
constraint exists
#19225
Conversation
This comment has been minimized.
This comment has been minimized.
Diff from mypy_primer, showing the effect of this PR on open source code: core (https://github.com/home-assistant/core)
+ homeassistant/core.py:2342: error: Unused "type: ignore" comment [unused-ignore]
+ homeassistant/scripts/benchmark/__init__.py:144: error: Unused "type: ignore" comment [unused-ignore]
+ homeassistant/scripts/benchmark/__init__.py:144: error: Argument 2 to "async_fire" of "EventBus" has incompatible type "dict[str, object]"; expected "EventStateChangedData | None" [arg-type]
+ homeassistant/scripts/benchmark/__init__.py:144: note: Error code "arg-type" not covered by "type: ignore" comment
+ homeassistant/scripts/benchmark/__init__.py:177: error: Unused "type: ignore" comment [unused-ignore]
+ homeassistant/scripts/benchmark/__init__.py:177: error: Argument 2 to "async_fire" of "EventBus" has incompatible type "dict[str, object]"; expected "EventStateChangedData | None" [arg-type]
+ homeassistant/scripts/benchmark/__init__.py:177: note: Error code "arg-type" not covered by "type: ignore" comment
+ homeassistant/scripts/benchmark/__init__.py:215: error: Unused "type: ignore" comment [unused-ignore]
+ homeassistant/scripts/benchmark/__init__.py:215: error: Argument 2 to "async_fire" of "EventBus" has incompatible type "dict[str, object]"; expected "EventStateChangedData | None" [arg-type]
+ homeassistant/scripts/benchmark/__init__.py:215: note: Error code "arg-type" not covered by "type: ignore" comment
|
Do you think there's any neat way to handle prioritization in such a general way that it solves this too? (i.e. marking constraints as higher quality than others) I did some basic version of that in #18958 and I would be happy if there's a method that generalizes to solve both this issue and that issue. |
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.
Never mind I thought more about my comment and any nice generalizations I can think of would rely on the dict
argument being inferred as a TypedDict
. I think this makes sense.
It looks like literals don't work in a similar fashion either, should we preemptively add support?
a_lit = A[Literal[1]]()
f(a_lit, 1)
Hm, I don't see any straightforward solution that could set constraints priorities reliably. But your Literal suggestion sounds interesting, I'll try to expand this PR tomorrow to cover this case |
Fixes #19201.
When inferring callable constraints, excludes constraints with
dict
target when other constraints haveTypedDict
type. The right way to do this would be to allow backtracking in meet and join (so thatdict
can be promoted toTypedDict
if possible), but that seems to be way more difficult and needs significant refactoring first.This should be safe as we never rely solely on solutions, such inference is followed by actually checking all arguments, so any incompatibilities will still be reported.