Skip to content

Commit c93c828

Browse files
committed
Fix
1 parent 6c921c5 commit c93c828

File tree

1 file changed

+21
-20
lines changed
  • crates/ty_python_semantic/src/types

1 file changed

+21
-20
lines changed

crates/ty_python_semantic/src/types/infer.rs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,28 +1136,29 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
11361136

11371137
kw_only_field_names.reverse();
11381138

1139-
if let (Some(first_field_name), other_fields) =
1140-
(kw_only_field_names.pop(), kw_only_field_names)
1141-
{
1142-
// TODO: The fields should be displayed in a subdiagnostic.
1143-
if let Some(builder) = self
1144-
.context
1145-
.report_lint(&DUPLICATE_KW_ONLY, &class_node.name)
1146-
{
1147-
let mut diagnostic = builder.into_diagnostic(format_args!(
1148-
"Dataclass has more than one field annotated with `KW_ONLY`"
1149-
));
1139+
match (kw_only_field_names.pop(), kw_only_field_names) {
1140+
(Some(first_field_name), other_fields) if !other_fields.is_empty() => {
1141+
// TODO: The fields should be displayed in a subdiagnostic.
1142+
if let Some(builder) = self
1143+
.context
1144+
.report_lint(&DUPLICATE_KW_ONLY, &class_node.name)
1145+
{
1146+
let mut diagnostic = builder.into_diagnostic(format_args!(
1147+
"Dataclass has more than one field annotated with `KW_ONLY`"
1148+
));
11501149

1151-
diagnostic
1152-
.info(format_args!("First `KW_ONLY` field: `{first_field_name}`"));
1153-
diagnostic.info(format_args!(
1154-
"Other fields: {}",
1155-
other_fields
1156-
.iter()
1157-
.map(|name| format!("`{name}`"))
1158-
.join(", ")
1159-
))
1150+
diagnostic
1151+
.info(format_args!("First `KW_ONLY` field: `{first_field_name}`"));
1152+
diagnostic.info(format_args!(
1153+
"Other fields: {}",
1154+
other_fields
1155+
.iter()
1156+
.map(|name| format!("`{name}`"))
1157+
.join(", ")
1158+
));
1159+
}
11601160
}
1161+
_ => {}
11611162
}
11621163
}
11631164
}

0 commit comments

Comments
 (0)