ty_python_semantic: update "no matching overload" diagnostic test
It looks like support for `@overload` has been added since this test was created, so we remove the TODO and add a snippet (from #274).
This commit is contained in:
committed by
Andrew Gallant
parent
2e94d37275
commit
0230cbac2c
@@ -4,11 +4,15 @@
|
||||
|
||||
## Calls to overloaded functions
|
||||
|
||||
TODO: Note that we do not yet support the `@overload` decorator to define overloaded functions in
|
||||
real Python code. We are instead testing a special-cased function where we create an overloaded
|
||||
signature internally. Update this to an `@overload` function in the Python snippet itself once we
|
||||
can.
|
||||
|
||||
```py
|
||||
type("Foo", ()) # error: [no-matching-overload]
|
||||
from typing import overload
|
||||
|
||||
@overload
|
||||
def f(x: int) -> int: ...
|
||||
@overload
|
||||
def f(x: str) -> str: ...
|
||||
def f(x: int | str) -> int | str:
|
||||
return x
|
||||
|
||||
f(b"foo") # error: [no-matching-overload]
|
||||
```
|
||||
|
||||
@@ -12,18 +12,31 @@ mdtest path: crates/ty_python_semantic/resources/mdtest/diagnostics/no_matching_
|
||||
## mdtest_snippet.py
|
||||
|
||||
```
|
||||
1 | type("Foo", ()) # error: [no-matching-overload]
|
||||
1 | from typing import overload
|
||||
2 |
|
||||
3 | @overload
|
||||
4 | def f(x: int) -> int: ...
|
||||
5 |
|
||||
6 | @overload
|
||||
7 | def f(x: str) -> str: ...
|
||||
8 |
|
||||
9 | def f(x: int | str) -> int | str:
|
||||
10 | return x
|
||||
11 |
|
||||
12 | f(b"foo") # error: [no-matching-overload]
|
||||
```
|
||||
|
||||
# Diagnostics
|
||||
|
||||
```
|
||||
error[no-matching-overload]: No overload of class `type` matches arguments
|
||||
--> src/mdtest_snippet.py:1:1
|
||||
|
|
||||
1 | type("Foo", ()) # error: [no-matching-overload]
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
|
||||
error[no-matching-overload]: No overload of function `f` matches arguments
|
||||
--> src/mdtest_snippet.py:12:1
|
||||
|
|
||||
10 | return x
|
||||
11 |
|
||||
12 | f(b"foo") # error: [no-matching-overload]
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
info: rule `no-matching-overload` is enabled by default
|
||||
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user