-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[ty] Surface matched overload diagnostic directly #18452
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d1a613a
[ty] Surface matched overload diagnostics directly
dhruvmanila cbc57ba
Rename, docs
dhruvmanila 1064e43
Include method wrapper, avoid direct indexing
dhruvmanila 8dd0775
Snapshot the diagnostic
dhruvmanila 486ce1c
Update union call diagnostic test
dhruvmanila 73df4ac
Add dedicated snapshot diagnostics tests
dhruvmanila 7e809fd
Remove snapshot diagnostic from call test
dhruvmanila 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 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
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
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
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
168 changes: 168 additions & 0 deletions
168
crates/ty_python_semantic/resources/mdtest/diagnostics/single_matching_overload.md
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
# Single matching overload | ||
|
||
<!-- snapshot-diagnostics --> | ||
|
||
## Limited number of overloads | ||
|
||
`overloaded.pyi`: | ||
|
||
```pyi | ||
from typing import overload | ||
|
||
@overload | ||
def f() -> None: ... | ||
@overload | ||
def f(x: int) -> int: ... | ||
@overload | ||
def f(x: int, y: int) -> int: ... | ||
``` | ||
|
||
```py | ||
from overloaded import f | ||
|
||
f("a") # error: [invalid-argument-type] | ||
``` | ||
|
||
## Call to function with too many unmatched overloads | ||
|
||
This has an excessive number of overloads to the point that ty will cut off the list in the | ||
diagnostic and emit a message stating the number of omitted overloads. | ||
|
||
`overloaded.pyi`: | ||
|
||
```pyi | ||
from typing import overload | ||
|
||
@overload | ||
def foo(a: int): ... | ||
@overload | ||
def foo(a: int, b: int, c: int): ... | ||
@overload | ||
def foo(a: str, b: int, c: int): ... | ||
@overload | ||
def foo(a: int, b: str, c: int): ... | ||
@overload | ||
def foo(a: int, b: int, c: str): ... | ||
@overload | ||
def foo(a: str, b: str, c: int): ... | ||
@overload | ||
def foo(a: int, b: str, c: str): ... | ||
@overload | ||
def foo(a: str, b: str, c: str): ... | ||
@overload | ||
def foo(a: int, b: int, c: int): ... | ||
@overload | ||
def foo(a: float, b: int, c: int): ... | ||
@overload | ||
def foo(a: int, b: float, c: int): ... | ||
@overload | ||
def foo(a: int, b: int, c: float): ... | ||
@overload | ||
def foo(a: float, b: float, c: int): ... | ||
@overload | ||
def foo(a: int, b: float, c: float): ... | ||
@overload | ||
def foo(a: float, b: float, c: float): ... | ||
@overload | ||
def foo(a: str, b: str, c: str): ... | ||
@overload | ||
def foo(a: float, b: str, c: str): ... | ||
@overload | ||
def foo(a: str, b: float, c: str): ... | ||
@overload | ||
def foo(a: str, b: str, c: float): ... | ||
@overload | ||
def foo(a: float, b: float, c: str): ... | ||
@overload | ||
def foo(a: str, b: float, c: float): ... | ||
@overload | ||
def foo(a: float, b: float, c: float): ... | ||
@overload | ||
def foo(a: list[int], b: list[int], c: list[int]): ... | ||
@overload | ||
def foo(a: list[str], b: list[int], c: list[int]): ... | ||
@overload | ||
def foo(a: list[int], b: list[str], c: list[int]): ... | ||
@overload | ||
def foo(a: list[int], b: list[int], c: list[str]): ... | ||
@overload | ||
def foo(a: list[str], b: list[str], c: list[int]): ... | ||
@overload | ||
def foo(a: list[int], b: list[str], c: list[str]): ... | ||
@overload | ||
def foo(a: list[str], b: list[str], c: list[str]): ... | ||
@overload | ||
def foo(a: list[int], b: list[int], c: list[int]): ... | ||
@overload | ||
def foo(a: list[float], b: list[int], c: list[int]): ... | ||
@overload | ||
def foo(a: list[int], b: list[float], c: list[int]): ... | ||
@overload | ||
def foo(a: list[int], b: list[int], c: list[float]): ... | ||
@overload | ||
def foo(a: list[float], b: list[float], c: list[int]): ... | ||
@overload | ||
def foo(a: list[int], b: list[float], c: list[float]): ... | ||
@overload | ||
def foo(a: list[float], b: list[float], c: list[float]): ... | ||
@overload | ||
def foo(a: list[str], b: list[str], c: list[str]): ... | ||
@overload | ||
def foo(a: list[float], b: list[str], c: list[str]): ... | ||
@overload | ||
def foo(a: list[str], b: list[float], c: list[str]): ... | ||
@overload | ||
def foo(a: list[str], b: list[str], c: list[float]): ... | ||
@overload | ||
def foo(a: list[float], b: list[float], c: list[str]): ... | ||
@overload | ||
def foo(a: list[str], b: list[float], c: list[float]): ... | ||
@overload | ||
def foo(a: list[float], b: list[float], c: list[float]): ... | ||
@overload | ||
def foo(a: bool, b: bool, c: bool): ... | ||
@overload | ||
def foo(a: str, b: bool, c: bool): ... | ||
@overload | ||
def foo(a: bool, b: str, c: bool): ... | ||
@overload | ||
def foo(a: bool, b: bool, c: str): ... | ||
@overload | ||
def foo(a: str, b: str, c: bool): ... | ||
@overload | ||
def foo(a: bool, b: str, c: str): ... | ||
@overload | ||
def foo(a: str, b: str, c: str): ... | ||
@overload | ||
def foo(a: int, b: int, c: int): ... | ||
@overload | ||
def foo(a: bool, b: int, c: int): ... | ||
@overload | ||
def foo(a: int, b: bool, c: int): ... | ||
@overload | ||
def foo(a: int, b: int, c: bool): ... | ||
@overload | ||
def foo(a: bool, b: bool, c: int): ... | ||
@overload | ||
def foo(a: int, b: bool, c: bool): ... | ||
@overload | ||
def foo(a: str, b: str, c: str): ... | ||
@overload | ||
def foo(a: float, b: bool, c: bool): ... | ||
@overload | ||
def foo(a: bool, b: float, c: bool): ... | ||
@overload | ||
def foo(a: bool, b: bool, c: float): ... | ||
@overload | ||
def foo(a: float, b: float, c: bool): ... | ||
@overload | ||
def foo(a: bool, b: float, c: float): ... | ||
``` | ||
|
||
```py | ||
from typing import overload | ||
|
||
from overloaded import foo | ||
|
||
foo("foo") # error: [invalid-argument-type] | ||
``` |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
This test case was missing in the original implementation so just wanted to make sure that we still follow the algorithm correctly with the logic in this PR.