diff --git a/crates/ty_python_semantic/resources/mdtest/diagnostics/union_call.md b/crates/ty_python_semantic/resources/mdtest/diagnostics/union_call.md index 4f406c165f..c6f8cd803a 100644 --- a/crates/ty_python_semantic/resources/mdtest/diagnostics/union_call.md +++ b/crates/ty_python_semantic/resources/mdtest/diagnostics/union_call.md @@ -112,7 +112,7 @@ def _(n: int): # error: [too-many-positional-arguments] # error: [invalid-argument-type] "Argument to function `f2` is incorrect: Expected `str`, found `Literal[3]`" # error: [missing-argument] - # error: [invalid-argument-type] "Argument to function `f4` is incorrect: Argument type `Literal[3]` does not satisfy upper bound of type variable `T`" + # error: [invalid-argument-type] "Argument to function `f4` is incorrect: Argument type `Literal[3]` does not satisfy upper bound `str` of type variable `T`" # error: [invalid-argument-type] "Argument to function `f5` is incorrect: Expected `str`, found `Literal[3]`" # error: [no-matching-overload] "No overload of function `f6` matches arguments" # error: [call-non-callable] "Object of type `Literal[5]` is not callable" diff --git a/crates/ty_python_semantic/resources/mdtest/snapshots/functions.md_-_Generic_functions___L…_-_Inferring_a_bound_ty…_(d50204b9d91b7bd1).snap b/crates/ty_python_semantic/resources/mdtest/snapshots/functions.md_-_Generic_functions___L…_-_Inferring_a_bound_ty…_(d50204b9d91b7bd1).snap index 3831ad8e67..f5e6aa220a 100644 --- a/crates/ty_python_semantic/resources/mdtest/snapshots/functions.md_-_Generic_functions___L…_-_Inferring_a_bound_ty…_(d50204b9d91b7bd1).snap +++ b/crates/ty_python_semantic/resources/mdtest/snapshots/functions.md_-_Generic_functions___L…_-_Inferring_a_bound_ty…_(d50204b9d91b7bd1).snap @@ -74,7 +74,7 @@ error[invalid-argument-type]: Argument to function `f` is incorrect 10 | reveal_type(f(True)) # revealed: Literal[True] 11 | # error: [invalid-argument-type] 12 | reveal_type(f("string")) # revealed: Unknown - | ^^^^^^^^ Argument type `Literal["string"]` does not satisfy upper bound of type variable `T` + | ^^^^^^^^ Argument type `Literal["string"]` does not satisfy upper bound `int` of type variable `T` | info: Type variable defined here --> src/mdtest_snippet.py:4:1 diff --git a/crates/ty_python_semantic/resources/mdtest/snapshots/functions.md_-_Generic_functions___L…_-_Inferring_a_constrai…_(48ab83f977c109b4).snap b/crates/ty_python_semantic/resources/mdtest/snapshots/functions.md_-_Generic_functions___L…_-_Inferring_a_constrai…_(48ab83f977c109b4).snap index f0223b5e64..bcba88dbd9 100644 --- a/crates/ty_python_semantic/resources/mdtest/snapshots/functions.md_-_Generic_functions___L…_-_Inferring_a_constrai…_(48ab83f977c109b4).snap +++ b/crates/ty_python_semantic/resources/mdtest/snapshots/functions.md_-_Generic_functions___L…_-_Inferring_a_constrai…_(48ab83f977c109b4).snap @@ -89,7 +89,7 @@ error[invalid-argument-type]: Argument to function `f` is incorrect 11 | reveal_type(f(None)) # revealed: None 12 | # error: [invalid-argument-type] 13 | reveal_type(f("string")) # revealed: Unknown - | ^^^^^^^^ Argument type `Literal["string"]` does not satisfy constraints of type variable `T` + | ^^^^^^^^ Argument type `Literal["string"]` does not satisfy constraints (`int`, `None`) of type variable `T` | info: Type variable defined here --> src/mdtest_snippet.py:4:1 diff --git a/crates/ty_python_semantic/resources/mdtest/snapshots/functions.md_-_Generic_functions___P…_-_Inferring_a_bound_ty…_(5935d14c26afe407).snap b/crates/ty_python_semantic/resources/mdtest/snapshots/functions.md_-_Generic_functions___P…_-_Inferring_a_bound_ty…_(5935d14c26afe407).snap index fc5bb331f1..a4dd346d6c 100644 --- a/crates/ty_python_semantic/resources/mdtest/snapshots/functions.md_-_Generic_functions___P…_-_Inferring_a_bound_ty…_(5935d14c26afe407).snap +++ b/crates/ty_python_semantic/resources/mdtest/snapshots/functions.md_-_Generic_functions___P…_-_Inferring_a_bound_ty…_(5935d14c26afe407).snap @@ -71,7 +71,7 @@ error[invalid-argument-type]: Argument to function `f` is incorrect 7 | reveal_type(f(True)) # revealed: Literal[True] 8 | # error: [invalid-argument-type] 9 | reveal_type(f("string")) # revealed: Unknown - | ^^^^^^^^ Argument type `Literal["string"]` does not satisfy upper bound of type variable `T` + | ^^^^^^^^ Argument type `Literal["string"]` does not satisfy upper bound `int` of type variable `T` | info: Type variable defined here --> src/mdtest_snippet.py:3:7 diff --git a/crates/ty_python_semantic/resources/mdtest/snapshots/functions.md_-_Generic_functions___P…_-_Inferring_a_constrai…_(d2c475fccc70a8e2).snap b/crates/ty_python_semantic/resources/mdtest/snapshots/functions.md_-_Generic_functions___P…_-_Inferring_a_constrai…_(d2c475fccc70a8e2).snap index 8a961a23fc..24ef2ebfb0 100644 --- a/crates/ty_python_semantic/resources/mdtest/snapshots/functions.md_-_Generic_functions___P…_-_Inferring_a_constrai…_(d2c475fccc70a8e2).snap +++ b/crates/ty_python_semantic/resources/mdtest/snapshots/functions.md_-_Generic_functions___P…_-_Inferring_a_constrai…_(d2c475fccc70a8e2).snap @@ -86,7 +86,7 @@ error[invalid-argument-type]: Argument to function `f` is incorrect 8 | reveal_type(f(None)) # revealed: None 9 | # error: [invalid-argument-type] 10 | reveal_type(f("string")) # revealed: Unknown - | ^^^^^^^^ Argument type `Literal["string"]` does not satisfy constraints of type variable `T` + | ^^^^^^^^ Argument type `Literal["string"]` does not satisfy constraints (`int`, `None`) of type variable `T` | info: Type variable defined here --> src/mdtest_snippet.py:3:7 diff --git a/crates/ty_python_semantic/resources/mdtest/snapshots/union_call.md_-_Calling_a_union_of_f…_-_Try_to_cover_all_pos…_-_Cover_non-keyword_re…_(707b284610419a54).snap b/crates/ty_python_semantic/resources/mdtest/snapshots/union_call.md_-_Calling_a_union_of_f…_-_Try_to_cover_all_pos…_-_Cover_non-keyword_re…_(707b284610419a54).snap index 52a55ed12c..86e63f2a35 100644 --- a/crates/ty_python_semantic/resources/mdtest/snapshots/union_call.md_-_Calling_a_union_of_f…_-_Try_to_cover_all_pos…_-_Cover_non-keyword_re…_(707b284610419a54).snap +++ b/crates/ty_python_semantic/resources/mdtest/snapshots/union_call.md_-_Calling_a_union_of_f…_-_Try_to_cover_all_pos…_-_Cover_non-keyword_re…_(707b284610419a54).snap @@ -66,7 +66,7 @@ mdtest path: crates/ty_python_semantic/resources/mdtest/diagnostics/union_call.m 52 | # error: [too-many-positional-arguments] 53 | # error: [invalid-argument-type] "Argument to function `f2` is incorrect: Expected `str`, found `Literal[3]`" 54 | # error: [missing-argument] -55 | # error: [invalid-argument-type] "Argument to function `f4` is incorrect: Argument type `Literal[3]` does not satisfy upper bound of type variable `T`" +55 | # error: [invalid-argument-type] "Argument to function `f4` is incorrect: Argument type `Literal[3]` does not satisfy upper bound `str` of type variable `T`" 56 | # error: [invalid-argument-type] "Argument to function `f5` is incorrect: Expected `str`, found `Literal[3]`" 57 | # error: [no-matching-overload] "No overload of function `f6` matches arguments" 58 | # error: [call-non-callable] "Object of type `Literal[5]` is not callable" @@ -188,7 +188,7 @@ error[invalid-argument-type]: Argument to function `f4` is incorrect 58 | # error: [call-non-callable] "Object of type `Literal[5]` is not callable" 59 | # error: [call-non-callable] "Object of type `PossiblyNotCallable` is not callable (possibly unbound `__call__` method)" 60 | x = f(3) - | ^ Argument type `Literal[3]` does not satisfy upper bound of type variable `T` + | ^ Argument type `Literal[3]` does not satisfy upper bound `str` of type variable `T` | info: Type variable defined here --> src/mdtest_snippet.py:13:8 diff --git a/crates/ty_python_semantic/src/types/call/bind.rs b/crates/ty_python_semantic/src/types/call/bind.rs index b027d5fef2..25fdce5e09 100644 --- a/crates/ty_python_semantic/src/types/call/bind.rs +++ b/crates/ty_python_semantic/src/types/call/bind.rs @@ -3086,14 +3086,20 @@ impl<'db> BindingError<'db> { String::new() } )); - diag.set_primary_message(format_args!( - "Argument type `{argument_ty_display}` does not satisfy {} of type variable `{}`", - match error { - SpecializationError::MismatchedBound {..} => "upper bound", - SpecializationError::MismatchedConstraint {..} => "constraints", - }, - typevar.name(context.db()), - )); + + let typevar_name = typevar.name(context.db()); + match error { + SpecializationError::MismatchedBound { .. } => { + diag.set_primary_message(format_args!("Argument type `{argument_ty_display}` does not satisfy upper bound `{}` of type variable `{typevar_name}`", + typevar.upper_bound(context.db()).expect("type variable should have an upper bound if this error occurs").display(context.db()) + )); + } + SpecializationError::MismatchedConstraint { .. } => { + diag.set_primary_message(format_args!("Argument type `{argument_ty_display}` does not satisfy constraints ({}) of type variable `{typevar_name}`", + typevar.constraints(context.db()).expect("type variable should have constraints if this error occurs").iter().map(|ty| format!("`{}`", ty.display(context.db()))).join(", ") + )); + } + } if let Some(typevar_definition) = typevar.definition(context.db()) { let module = parsed_module(context.db(), typevar_definition.file(context.db()))