From 0230cbac2c2b135a7ef7160fac1220ad4be2c3c2 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Tue, 13 May 2025 11:23:19 -0400 Subject: [PATCH] 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). --- .../diagnostics/no_matching_overload.md | 16 ++++++----- ..._Calls_to_overloaded_…_(3553d085684e16a0).snap | 27 ++++++++++++++----- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/crates/ty_python_semantic/resources/mdtest/diagnostics/no_matching_overload.md b/crates/ty_python_semantic/resources/mdtest/diagnostics/no_matching_overload.md index d0d3c916df..9dc6265df2 100644 --- a/crates/ty_python_semantic/resources/mdtest/diagnostics/no_matching_overload.md +++ b/crates/ty_python_semantic/resources/mdtest/diagnostics/no_matching_overload.md @@ -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] ``` diff --git a/crates/ty_python_semantic/resources/mdtest/snapshots/no_matching_overload…_-_No_matching_overload…_-_Calls_to_overloaded_…_(3553d085684e16a0).snap b/crates/ty_python_semantic/resources/mdtest/snapshots/no_matching_overload…_-_No_matching_overload…_-_Calls_to_overloaded_…_(3553d085684e16a0).snap index 4f3f262bcb..28389124c9 100644 --- a/crates/ty_python_semantic/resources/mdtest/snapshots/no_matching_overload…_-_No_matching_overload…_-_Calls_to_overloaded_…_(3553d085684e16a0).snap +++ b/crates/ty_python_semantic/resources/mdtest/snapshots/no_matching_overload…_-_No_matching_overload…_-_Calls_to_overloaded_…_(3553d085684e16a0).snap @@ -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 ```