Infer type var tuple contents in more situations#18958
Open
A5rocks wants to merge 8 commits intopython:masterfrom
Open
Infer type var tuple contents in more situations#18958A5rocks wants to merge 8 commits intopython:masterfrom
A5rocks wants to merge 8 commits intopython:masterfrom
Conversation
3 tasks
This comment has been minimized.
This comment has been minimized.
Collaborator
Author
|
The only bad change in mypy primer is: ... and I'm not quite sure if there's a good way to solve this. We could check whether constraints interfere with each other and only if they do prefer the higher quality ones? That sounds slow, though. (EDIT: I did that, but again I'm not confident it's right) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Collaborator
Author
|
@ilevkivskyi this is my best guess at a mechanism that would handle |
This comment has been minimized.
This comment has been minimized.
Contributor
|
Diff from mypy_primer, showing the effect of this PR on open source code: sockeye (https://github.com/awslabs/sockeye)
+ sockeye/layers.py:530: error: Unused "type: ignore" comment [unused-ignore]
+ sockeye/layers.py:873: error: Unused "type: ignore" comment [unused-ignore]
core (https://github.com/home-assistant/core)
+ homeassistant/util/signal_type.pyi:57: error: Unused "type: ignore" comment [unused-ignore]
+ homeassistant/util/signal_type.pyi:57: error: Argument 2 to "async_dispatcher_send" has incompatible type "SignalType[int]"; expected "SignalType[str]" [arg-type]
+ homeassistant/util/signal_type.pyi:57: note: Error code "arg-type" not covered by "type: ignore" comment
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supersedes #17512 as I figured out how to handle this case in a more general manner.
This PR fixes #16522. It adds a mechanism for constraints to be discarded if they are less likely to be correct: for instance, if you pass
f(x: int, y: str = "42")toCallable[[Unpack[Ts]], None]it's not clear whetheryshould be included in an unpackedTypeVarTuple. This PR makes it such thatfunction_using_typevartuple(f, 42)discards constraints based onf.Alternatively, I could make it such that TypeVarTuples can be linked to Parameters. I haven't done that since it's a larger and slightly strange change, but if that works better I would be happy to.