-
-
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 tuple subtyping #16073
Closed
Closed
Fix tuple subtyping #16073
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,9 +60,7 @@ reveal_type(f(f_args3)) # N: Revealed type is "Tuple[builtins.str, builtins.str | |
f(empty) # E: Argument 1 to "f" has incompatible type "Tuple[()]"; expected "Tuple[int]" | ||
f(bad_args) # E: Argument 1 to "f" has incompatible type "Tuple[str, str]"; expected "Tuple[int, str]" | ||
|
||
# The reason for error in subtle: actual can be empty, formal cannot. | ||
reveal_type(f(var_len_tuple)) # N: Revealed type is "Tuple[builtins.str, Unpack[builtins.tuple[builtins.int, ...]]]" \ | ||
# E: Argument 1 to "f" has incompatible type "Tuple[int, ...]"; expected "Tuple[int, Unpack[Tuple[int, ...]]]" | ||
reveal_type(f(var_len_tuple)) # N: Revealed type is "Tuple[builtins.str, Unpack[builtins.tuple[builtins.int, ...]]]" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error is correct, because |
||
|
||
g_args: Tuple[str, int] | ||
reveal_type(g(g_args)) # N: Revealed type is "Tuple[builtins.str, builtins.str]" | ||
|
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.
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.
Sorry, but this is wrong. IIUC this will make
tuple[object, ...]
a subtype oftuple[int, str]
. While eventuple[int, ...]
shoul not be a subtype oftuple[int, int]
. Really onlytuple[Any, ...]
should be a subtype of saytuple[int, int]
. This is the same as we consider*args: Any
in callables very differently from*args: object
or*args: int
.Note btw this question will appear even broader in context of my upcoming PR for variadic types, e.g. should we also special case
Foo[int, *tuple[Any, ...], str]
similarly in spirit to extending the special-casing of trivial arguments to trivial suffix in #15913. (Btw I would say yes, but it should be a separate PR after we gain more experience).Also I bet most of the unused type ignores in mypy primer are from situations like:
(as e.g. for ignore in mypy itself). See also #1178. The proper way to solve such issues is by finally completing #10367. Unfortunately author is not responding anymore, so one of us may need to complete the PR, since it is an important one.