[ty] more simplification of infer_parameterized_legacy_typing_alias (#18526)

Address post-land review on https://github.com/astral-sh/ruff/pull/18489
This commit is contained in:
Carl Meyer 2025-06-10 13:22:25 -07:00 committed by GitHub
parent b21ac567e1
commit eb60bd64fd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -9108,12 +9108,12 @@ impl<'db> TypeInferenceBuilder<'db, '_> {
class: KnownClass, class: KnownClass,
) -> Type<'db> { ) -> Type<'db> {
let arguments = &*subscript_node.slice; let arguments = &*subscript_node.slice;
let (args, args_number) = if let ast::Expr::Tuple(t) = arguments { let args = if let ast::Expr::Tuple(t) = arguments {
(t.iter(), t.len()) &*t.elts
} else { } else {
(std::slice::from_ref(arguments).iter(), 1) std::slice::from_ref(arguments)
}; };
if args_number != expected_arg_count { if args.len() != expected_arg_count {
if let Some(builder) = self.context.report_lint(&INVALID_TYPE_FORM, subscript_node) { if let Some(builder) = self.context.report_lint(&INVALID_TYPE_FORM, subscript_node) {
let noun = if expected_arg_count == 1 { let noun = if expected_arg_count == 1 {
"argument" "argument"
@ -9122,14 +9122,14 @@ impl<'db> TypeInferenceBuilder<'db, '_> {
}; };
builder.into_diagnostic(format_args!( builder.into_diagnostic(format_args!(
"Legacy alias `{alias}` expected exactly {expected_arg_count} {noun}, \ "Legacy alias `{alias}` expected exactly {expected_arg_count} {noun}, \
got {args_number}", got {}",
args.len()
)); ));
} }
} }
let ty = class.to_specialized_instance( let ty = class.to_specialized_instance(
self.db(), self.db(),
args.into_iter() args.iter().map(|node| self.infer_type_expression(node)),
.map(|node| self.infer_type_expression(node)),
); );
if arguments.is_tuple_expr() { if arguments.is_tuple_expr() {
self.store_expression_type(arguments, ty); self.store_expression_type(arguments, ty);