Repository: astral-sh/ruff
File: crates/ty_python_semantic/src/types/call/bind.rs (Rust)

Code before:
                                .positional()
                                .skip(self.next_positional)
                                .all(|parameter| parameter.default_type().is_some()) =>
                    {
                        let tuple_specs = union
                            .elements(db)
                            .iter()
                            .map(|ty| {
                                ty.try_iterate(db).unwrap_or_else(|err| {
                                    Cow::Owned(TupleSpec::homogeneous(
                                        err.fallback_element_type(db),
                                    ))
                                })
                            })
                            .collect_vec();

                        let any_variable_length =
                            tuple_specs.iter().any(|spec| spec.len().is_variable());
                        let mut tuple_index = 0usize;

                        while self
                            .parameters
                            .get_positional(self.next_positional)
                            .is_some()
                        {
                            if any_variable_length
                                && self
                                    .explicit_keyword_parameters
                                    .contains(&self.next_positional)
                            {
                                break;
                            }

                            let Ok(tuple_index_i32) = i32::try_from(tuple_index) else {
                                break;
                            };

                            let positional_types = tuple_specs
                                .iter()
                                .filter_map(|tuple| tuple.py_index(db, tuple_index_i32).ok())
                                .collect_vec();

                            if positional_types.is_empty() {
                                break;
                            }

                            let argument_type =
                                UnionType::from_elements_leave_aliases(db, positional_types);

                            self.match_positional(
                                argument_index,

Review comment (suggestion):
It's not clear to me why this check should be conditioned on `any_variable_length` -- but I'm going to stop trying to verify the details of the logic in the current PR until/unless we confirm that this can't be implemented according to the less-duplicative strategy I suggested in another comment.

Code after:

                // If only one overload passed arity check, report its errors directly.
                if let Some(matching_overload_index) = self.matching_overload_before_type_checking {
                    let callable_description =
                        CallableDescription::new(context.db(), self.signature_type);
                    let matching_overload =
                        function_type_and_kind.map(|(kind, function)| MatchingOverloadLiteral {
                            index: matching_overload_index,
                            kind,
                            function,
                        });
                    self.overloads[matching_overload_index].report_diagnostics(
                        context,
                        node,
                        self.signature_type,
                        callable_description.as_ref(),
                        compound_diag,
                        matching_overload.as_ref(),
                    );
                    return;
                }

                // If multiple overloads passed arity check but only one matched types
                // (possibly with semantic errors), report its errors directly instead
                // of the generic "no matching overload" message.
                if let MatchingOverloadIndex::Single(matching_overload_index) =
                    self.matching_overload_index()
                {
                    let callable_description =
                        CallableDescription::new(context.db(), self.signature_type);
                    let matching_overload =
                        function_type_and_kind.map(|(kind, function)| MatchingOverloadLiteral {
                            index: matching_overload_index,
                            kind,
                            function,
                        });
                    self.overloads[matching_overload_index].report_diagnostics(
                        context,
                        node,
                        self.signature_type,
                        callable_description.as_ref(),
                        compound_diag,
                        matching_overload.as_ref(),
                    );
                    return;
                }

                let Some(builder) = context.report_lint(&NO_MATCHING_OVERLOAD, node) else {
                    return;
                };
                let callable_description =