mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 18:58:04 +00:00
ty_python_semantic: rejigger handling of overload error conditions
I found the previous code somewhat harder to read. Namely, a `for` loop was being used to encode "execute zero or one times, but not more." Which is sometimes okay, but it seemed clearer to me to use more explicit case analysis here. This should have no behavioral changes.
This commit is contained in:
parent
0230cbac2c
commit
bd5b7f415f
1 changed files with 19 additions and 15 deletions
|
@ -1086,9 +1086,25 @@ impl<'db> CallableBinding<'db> {
|
|||
return;
|
||||
}
|
||||
|
||||
let callable_description = CallableDescription::new(context.db(), self.callable_type);
|
||||
if self.overloads.len() > 1 {
|
||||
if let Some(builder) = context.report_lint(&NO_MATCHING_OVERLOAD, node) {
|
||||
match self.overloads.as_slice() {
|
||||
[] => {}
|
||||
[overload] => {
|
||||
let callable_description =
|
||||
CallableDescription::new(context.db(), self.signature_type);
|
||||
overload.report_diagnostics(
|
||||
context,
|
||||
node,
|
||||
self.signature_type,
|
||||
callable_description.as_ref(),
|
||||
union_diag,
|
||||
);
|
||||
}
|
||||
_overloads => {
|
||||
let Some(builder) = context.report_lint(&NO_MATCHING_OVERLOAD, node) else {
|
||||
return;
|
||||
};
|
||||
let callable_description =
|
||||
CallableDescription::new(context.db(), self.callable_type);
|
||||
let mut diag = builder.into_diagnostic(format_args!(
|
||||
"No overload{} matches arguments",
|
||||
if let Some(CallableDescription { kind, name }) = callable_description {
|
||||
|
@ -1101,18 +1117,6 @@ impl<'db> CallableBinding<'db> {
|
|||
union_diag.add_union_context(context.db(), &mut diag);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
let callable_description = CallableDescription::new(context.db(), self.signature_type);
|
||||
for overload in &self.overloads {
|
||||
overload.report_diagnostics(
|
||||
context,
|
||||
node,
|
||||
self.signature_type,
|
||||
callable_description.as_ref(),
|
||||
union_diag,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue