diff --git a/conformance/third_party/conformance.exp b/conformance/third_party/conformance.exp index 35161953f3..105ba6f0c2 100644 --- a/conformance/third_party/conformance.exp +++ b/conformance/third_party/conformance.exp @@ -5019,7 +5019,7 @@ "code": -2, "column": 12, "concise_description": "`+` is not supported between `AnyStr` and `AnyStr`", - "description": "`+` is not supported between `AnyStr` and `AnyStr`\n No matching overload found for function `str.__add__` called with arguments: (AnyStr)\n Possible overloads:\n (value: LiteralString, /) -> LiteralString\n (value: str, /) -> str [closest match]", + "description": "`+` is not supported between `AnyStr` and `AnyStr`\n No matching overload found for function `str.__add__` called with arguments: (AnyStr)\n Possible overloads:\n def (value: LiteralString, /) -> LiteralString:\n ...\n def (value: str, /) -> str:# [closest match]\n ...", "line": 34, "name": "unsupported-operation", "severity": "error", @@ -8265,7 +8265,7 @@ "code": -2, "column": 1, "concise_description": "Cannot index into `Bytes`", - "description": "Cannot index into `Bytes`\n No matching overload found for function `Bytes.__getitem__` called with arguments: (Literal[''])\n Possible overloads:\n (__i: int, /) -> int [closest match]\n (__s: slice[Any, Any, Any], /) -> bytes", + "description": "Cannot index into `Bytes`\n No matching overload found for function `Bytes.__getitem__` called with arguments: (Literal[''])\n Possible overloads:\n def (__i: int, /) -> int:# [closest match]\n ...\n def (__s: slice[Any, Any, Any], /) -> bytes:\n ...", "line": 39, "name": "bad-index", "severity": "error", @@ -8447,7 +8447,7 @@ "code": -2, "column": 11, "concise_description": "No matching overload found for function `example1_1` called with arguments: ()", - "description": "No matching overload found for function `example1_1` called with arguments: ()\n Possible overloads:\n (x: int, y: str) -> int\n (x: str) -> str [closest match]", + "description": "No matching overload found for function `example1_1` called with arguments: ()\n Possible overloads:\n def (\n x: int,\n y: str\n) -> int:\n ...\n def (x: str) -> str:# [closest match]\n ...", "line": 38, "name": "no-matching-overload", "severity": "error", @@ -8458,7 +8458,7 @@ "code": -2, "column": 11, "concise_description": "No matching overload found for function `example1_1` called with arguments: (Literal[1], Literal[1])", - "description": "No matching overload found for function `example1_1` called with arguments: (Literal[1], Literal[1])\n Possible overloads:\n (x: int, y: str) -> int [closest match]\n (x: str) -> str", + "description": "No matching overload found for function `example1_1` called with arguments: (Literal[1], Literal[1])\n Possible overloads:\n def (\n x: int,\n y: str\n) -> int:# [closest match]\n ...\n def (x: str) -> str:\n ...", "line": 46, "name": "no-matching-overload", "severity": "error", @@ -8469,7 +8469,7 @@ "code": -2, "column": 11, "concise_description": "No matching overload found for function `example1_1` called with arguments: (Literal[1])", - "description": "No matching overload found for function `example1_1` called with arguments: (Literal[1])\n Possible overloads:\n (x: int, y: str) -> int [closest match]\n (x: str) -> str", + "description": "No matching overload found for function `example1_1` called with arguments: (Literal[1])\n Possible overloads:\n def (\n x: int,\n y: str\n) -> int:# [closest match]\n ...\n def (x: str) -> str:\n ...", "line": 51, "name": "no-matching-overload", "severity": "error", @@ -8480,7 +8480,7 @@ "code": -2, "column": 13, "concise_description": "No matching overload found for function `example2` called with arguments: (int | str, int | str, Literal[1])", - "description": "No matching overload found for function `example2` called with arguments: (int | str, int | str, Literal[1])\n Possible overloads:\n (x: int, y: str, z: int) -> str [closest match]\n (x: int, y: int, z: int) -> int", + "description": "No matching overload found for function `example2` called with arguments: (int | str, int | str, Literal[1])\n Possible overloads:\n def (\n x: int,\n y: str,\n z: int\n) -> str:# [closest match]\n ...\n def (\n x: int,\n y: int,\n z: int\n) -> int:\n ...", "line": 115, "name": "no-matching-overload", "severity": "error", @@ -11302,7 +11302,7 @@ "code": -2, "column": 10, "concise_description": "No matching overload found for function `A.update` called with arguments: (TypedDict[A])", - "description": "No matching overload found for function `A.update` called with arguments: (TypedDict[A])\n Possible overloads:\n (m: Partial[A], /) -> None [closest match]\n (m: Iterable[tuple[Literal['y'], int]], /) -> None\n (*, y: int = ...) -> None", + "description": "No matching overload found for function `A.update` called with arguments: (TypedDict[A])\n Possible overloads:\n def (m: Partial[A], /) -> None:# [closest match]\n ...\n def (m: Iterable[tuple[Literal['y'], int]], /) -> None:\n ...\n def (*, y: int = ...) -> None:\n ...", "line": 23, "name": "no-matching-overload", "severity": "error", diff --git a/conformance/third_party/conformance.result b/conformance/third_party/conformance.result index abc475c537..628a7dbb91 100644 --- a/conformance/third_party/conformance.result +++ b/conformance/third_party/conformance.result @@ -133,7 +133,7 @@ "Line 98: Expected 1 errors" ], "generics_basic.py": [ - "Line 34: Unexpected errors ['`+` is not supported between `AnyStr` and `AnyStr`\\n Argument `AnyStr` is not assignable to parameter `value` with type `Buffer` in function `bytes.__add__`\\n Protocol `Buffer` requires attribute `__buffer__`', '`+` is not supported between `AnyStr` and `AnyStr`\\n No matching overload found for function `str.__add__` called with arguments: (AnyStr)\\n Possible overloads:\\n (value: LiteralString, /) -> LiteralString\\n (value: str, /) -> str [closest match]', 'Returned type `bytes | Unknown` is not assignable to declared return type `AnyStr`']", + "Line 34: Unexpected errors ['`+` is not supported between `AnyStr` and `AnyStr`\\n Argument `AnyStr` is not assignable to parameter `value` with type `Buffer` in function `bytes.__add__`\\n Protocol `Buffer` requires attribute `__buffer__`', '`+` is not supported between `AnyStr` and `AnyStr`\\n No matching overload found for function `str.__add__` called with arguments: (AnyStr)\\n Possible overloads:\\n def (value: LiteralString, /) -> LiteralString:\\n ...\\n def (value: str, /) -> str:# [closest match]\\n ...', 'Returned type `bytes | Unknown` is not assignable to declared return type `AnyStr`']", "Line 67: Unexpected errors ['assert_type(MyStr, str) failed']", "Line 68: Unexpected errors ['assert_type(MyStr, str) failed', 'Argument `str` is not assignable to parameter `y` with type `MyStr` in function `concat`']" ], diff --git a/pyrefly/lib/alt/overload.rs b/pyrefly/lib/alt/overload.rs index e389127629..15024a6218 100644 --- a/pyrefly/lib/alt/overload.rs +++ b/pyrefly/lib/alt/overload.rs @@ -368,7 +368,7 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> { ]; for overload in overloads { let suffix = if overload.1.signature == closest_overload.func.1.signature { - " [closest match]" + "# [closest match]" } else { "" }; @@ -384,7 +384,8 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> { let signature = self .solver() .for_display(Type::Callable(Box::new(signature))); - msg.push(format!("{signature}{suffix}")); + let signature = signature.as_hover_string(); + msg.push(format!("def {signature}:{suffix}\n ...")); } // We intentionally discard closest_overload.call_errors. When no overload matches, // there's a high likelihood that the "closest" one by our heuristic isn't the right diff --git a/pyrefly/lib/test/overload.rs b/pyrefly/lib/test/overload.rs index 75710d8f90..d71b8446df 100644 --- a/pyrefly/lib/test/overload.rs +++ b/pyrefly/lib/test/overload.rs @@ -895,7 +895,7 @@ def f(x: int, y: int) -> int: ... def f(x: int, y: int = 0) -> int: return x + y -f(0, 1, 2) # E: (x: int, y: int) -> int [closest match] +f(0, 1, 2) # E: (\n x: int,\n y: int\n) -> int:# [closest match] "#, );