Skip to content

Commit 9426626

Browse files
rchen152facebook-github-bot
authored andcommitted
Don't include variable ids in inconsistent overload error messages
Summary: I noticed while looking at the errors pyrefly generates on mypy_primer that we're printing variable ids in our error messages about inconsistent overloads. This causes error messages to vary between pyrefly runs. Fixed by making sure that when we substitute fresh variables into a callable signature, we use the pre-substitution signature for error messages. Reviewed By: ndmitchell Differential Revision: D81898793 fbshipit-source-id: fd6c99a81525a5ba6c5510efe9905787e106baf2
1 parent 91a1d22 commit 9426626

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

pyrefly/lib/alt/function.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1109,7 +1109,7 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> {
11091109
&|| {
11101110
TypeCheckContext::of_kind(TypeCheckKind::OverloadInput(
11111111
overload_func.signature.clone(),
1112-
impl_func.signature.clone(),
1112+
impl_sig.clone(),
11131113
))
11141114
},
11151115
);

pyrefly/lib/test/overload.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,3 +688,23 @@ def foo(d: TD | int) -> None: ...
688688
assert_type(foo({ "x": "foo" }), Any) # E: No matching overload found for function `foo`
689689
"#,
690690
);
691+
692+
testcase!(
693+
test_generic_impl_input_inconsistent,
694+
r#"
695+
from typing import overload, TypeVar
696+
T = TypeVar("T")
697+
S = TypeVar("S")
698+
699+
# The implementation signature is intentionally inconsistent with this overload signature
700+
# (`exception` is kw-only in the implementation) so that we can test how legacy TypeVars are
701+
# printed in the error message.
702+
@overload
703+
def catch(exception: T) -> T: ... # E: Implementation signature `(f: S | None = None, *, exception: T) -> S | T` does not accept all arguments that overload signature `(exception: object) -> object` accepts
704+
705+
@overload
706+
def catch(f: S, *, exception: T) -> S | T: ...
707+
708+
def catch(f: S | None = None, *, exception: T) -> S | T: ...
709+
"#,
710+
);

0 commit comments

Comments
 (0)