Skip to content

Commit 6e17b63

Browse files
committed
Review findings
1 parent 766e13c commit 6e17b63

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

crates/ty_python_semantic/resources/mdtest/snapshots/assignment_diagnosti…_-_Subscript_assignment…_-_Possibly_missing_`__…_(efd3f0c02e9b89e9).snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ error[invalid-assignment]: Cannot assign to a subscript on an object of type `No
2727
| ^^^^^^^^^^^^^^^^^
2828
|
2929
info: The full type of the subscripted object is `dict[str, int] | None`
30-
help: `None` does not have a `__setitem__` method.
30+
info: `None` does not have a `__setitem__` method.
3131
info: rule `invalid-assignment` is enabled by default
3232
3333
```

crates/ty_python_semantic/src/types/infer/builder.rs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3794,18 +3794,18 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
37943794
let assigned_d = rhs_value_ty.display(db);
37953795
let object_d = object_ty.display(db);
37963796

3797+
let mut diagnostic = builder.into_diagnostic(format_args!(
3798+
"Invalid subscript assignment with key of type `{}` and value of \
3799+
type `{assigned_d}` on object of type `{object_d}`",
3800+
slice_ty.display(db),
3801+
));
3802+
37973803
// Special diagnostic for dictionaries
37983804
if let Some([expected_key_ty, expected_value_ty]) =
37993805
object_ty
38003806
.known_specialization(db, KnownClass::Dict)
38013807
.map(|s| s.types(db))
38023808
{
3803-
let mut diagnostic = builder.into_diagnostic(format_args!(
3804-
"Invalid subscript assignment with key of type `{}` and value of \
3805-
type `{assigned_d}` on object of type `{object_d}`",
3806-
slice_ty.display(db),
3807-
));
3808-
38093809
if !slice_ty.is_assignable_to(db, *expected_key_ty)
38103810
{
38113811
diagnostic.annotate(
@@ -3832,16 +3832,9 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
38323832
)),
38333833
);
38343834
}
3835-
3836-
attach_original_type_info(&mut diagnostic);
3837-
} else {
3838-
let mut diagnostic = builder.into_diagnostic(format_args!(
3839-
"Invalid subscript assignment with key of type `{}` and value of \
3840-
type `{assigned_d}` on object of type `{object_d}`",
3841-
slice_ty.display(db),
3842-
));
3843-
attach_original_type_info(&mut diagnostic);
38443835
}
3836+
3837+
attach_original_type_info(&mut diagnostic);
38453838
}
38463839
}
38473840
}
@@ -3889,7 +3882,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
38893882
object_ty.display(db),
38903883
));
38913884
} else {
3892-
diagnostic.help(format_args!(
3885+
diagnostic.info(format_args!(
38933886
"`{}` does not have a `__setitem__` method.",
38943887
object_ty.display(db),
38953888
));

0 commit comments

Comments
 (0)