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

Code before:
            return false;
        }

        let signatures = &callable.signatures(self.db).overloads;
        if signatures.is_empty() {
            return false;
        }

        let sub_arguments = if let Some(argument_index) = argument_index {
            self.arguments.start_from(argument_index)
        } else {
            CallArguments::none()
        };

        // Create Bindings with all overloads and perform full overload resolution
        let callable_binding =
            CallableBinding::from_overloads(self.signature_type, signatures.iter().cloned());
        let mut bindings = match Bindings::from(callable_binding)
            .match_parameters(self.db, &sub_arguments)
            .check_types(self.db, &sub_arguments, self.call_expression_tcx, &[])
        {
            Ok(bindings) => bindings,
            Err(CallError(_, bindings)) => *bindings,
        };
        let offset = argument_index.unwrap_or(0);
        bindings.apply_argument_index_offset(offset);

        // SAFETY: `bindings` was created from a single `CallableBinding` above.
        let callable_binding = bindings
            .single_element()
            .expect("ParamSpec sub-call should only contain a single CallableBinding");

        match callable_binding.matching_overload_index() {
            MatchingOverloadIndex::None => {
                if let [binding] = callable_binding.overloads() {
                    // This is not an overloaded function, so we can propagate its errors to the
                    // outer bindings.
                    self.errors.extend(binding.errors.iter().cloned());
                } else {
                    let index = callable_binding
                        .matching_overload_before_type_checking
                        .unwrap_or(0);
                    // TODO: We should also update the specialization for the `ParamSpec` to reflect
                    // the matching overload here.
                    self.errors
                        .extend(callable_binding.overloads()[index].errors.iter().cloned());
                }
            }
            MatchingOverloadIndex::Single(index) => {
                // TODO: We should also update the specialization for the `ParamSpec` to reflect the
                // matching overload here.

Review comment (suggestion):
We don't need to apply the offset if it's `None`, so we can skip that.

I'd recommend to avoid having this method on `Bindings` and instead just have it on the `BindingError` as it's very specific to this sub-call logic which only needs to update the index on the errors.

Code after:
            (CallArguments::none(), None)
        };

        // Create Bindings with all overloads and perform full overload resolution
        let callable_binding =
            CallableBinding::from_overloads(self.signature_type, signatures.iter().cloned());
        let bindings = match Bindings::from(callable_binding)
            .match_parameters(self.db, &sub_arguments)
            .check_types(self.db, &sub_arguments, self.call_expression_tcx, &[])
        {
            Ok(bindings) => bindings,
            Err(CallError(_, bindings)) => *bindings,
        };

        // SAFETY: `bindings` was created from a single `CallableBinding` above.
        let callable_binding = bindings
            .single_element()
            .expect("ParamSpec sub-call should only contain a single CallableBinding");

        match callable_binding.matching_overload_index() {
            MatchingOverloadIndex::None => {
                if let [binding] = callable_binding.overloads() {
                    // This is not an overloaded function, so we can propagate its errors to the
                    // outer bindings.
                    self.errors.extend(
                        binding
                            .errors
                            .iter()
                            .cloned()
                            .map(|err| err.maybe_apply_argument_index_offset(error_offset)),
                    );
                } else {
                    let index = callable_binding
                        .matching_overload_before_type_checking
                        .unwrap_or(0);
                    // TODO: We should also update the specialization for the `ParamSpec` to reflect
                    // the matching overload here.
                    self.errors.extend(
                        callable_binding.overloads()[index]
                            .errors
                            .iter()
                            .cloned()
                            .map(|err| err.maybe_apply_argument_index_offset(error_offset)),
                    );
                }
            }
            MatchingOverloadIndex::Single(index) => {
                // TODO: We should also update the specialization for the `ParamSpec` to reflect the
                // matching overload here.
                self.errors.extend(
                    callable_binding.overloads()[index]