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

Code before:

        // Extract signature details from all callable bindings
        bindings
            .into_iter()
            .flatten()
            .map(|binding| {
                let argument_to_parameter_mapping = binding.argument_matches().to_vec();
                let specialization = binding.specialization();
                let signature = binding.signature;
                let display_details = signature.display(model.db()).to_string_parts();
                let parameter_label_offsets = display_details.parameter_ranges;
                let parameter_names = display_details.parameter_names;
                let (parameter_kinds, parameter_types): (Vec<ParameterKind>, Vec<Type>) = signature
                    .parameters()
                    .iter()
                    .map(|param| {
                        // Apply the inferred specialization (if any) to resolve TypeVars
                        // in the annotated type. For example, if `_KT` was inferred as
                        // `str` from the call arguments, this turns `_KT` into `str`.
                        let ty = if let Some(spec) = specialization {
                            param
                                .annotated_type()
                                .apply_specialization(model.db(), spec)
                        } else {
                            param.annotated_type()
                        };
                        (param.kind().clone(), ty)
                    })
                    .unzip();

                CallSignatureDetails {
                    definition: signature.definition(),
                    signature,
                    label: display_details.label,
                    parameter_label_offsets,
                    parameter_names,
                    parameter_kinds,
                    parameter_types,
                    argument_to_parameter_mapping,
                }
            })
            .collect()
    } else {
        // Type is not callable, return empty signatures
        vec![]
    }
}

/// Given a call expression that has overloads, and whose overload is resolved to a
/// single option by its arguments, return the type of the Signature.
///

Review comment (suggestion):
I think this might be simpler as:

```suggestion
                        let mut ty = param.annotated_type();
                        if let Some(spec) = specialization {
                            ty = ty.apply_specialization(model.db(), spec);
                        }
```

Before this I had to carefully read each branch to check what the difference was.

Code after:
    /// Parameter kinds, useful to determine correct autocomplete suggestions.
    pub parameter_kinds: Vec<ParameterKind<'db>>,

    /// Annotated types of parameters. If no annotation was provided, this is `Unknown`.
    pub parameter_types: Vec<Type<'db>>,

    /// The definition where this callable was originally defined (useful for
    /// extracting docstrings).
    pub definition: Option<Definition<'db>>,

    /// Mapping from argument indices to parameter indices. This helps
    /// determine which parameter corresponds to which argument position.
    pub argument_to_parameter_mapping: Vec<MatchedArgument<'db>>,
}

impl<'db> CallSignatureDetails<'db> {
    fn from_binding(db: &'db dyn Db, binding: &crate::types::call::Binding<'db>) -> Self {
        let argument_to_parameter_mapping = binding.argument_matches().to_vec();
        let specialization = binding.specialization();
        let signature = binding.signature.clone();
        let display_details = signature.display(db).to_string_parts();
        let (parameter_kinds, parameter_types): (Vec<ParameterKind>, Vec<Type>) = signature
            .parameters()
            .iter()
            .map(|param| {
                // Apply the inferred specialization (if any) to resolve TypeVars
                // in the annotated type. For example, if `_KT` was inferred as
                // `str` from the call arguments, this turns `_KT` into `str`.
                let mut ty = param.annotated_type();
                if let Some(spec) = specialization {
                    ty = ty.apply_specialization(db, spec);
                }
                (param.kind().clone(), ty)
            })
            .unzip();

        CallSignatureDetails {
            definition: signature.definition(),
            signature,
            label: display_details.label,
            parameter_label_offsets: display_details.parameter_ranges,
            parameter_names: display_details.parameter_names,
            parameter_kinds,
            parameter_types,
            argument_to_parameter_mapping,
        }
    }

    fn get_definition_parameter_range(&self, db: &dyn Db, name: &str) -> Option<FileRange> {
        let definition = self.signature.definition()?;
        let file = definition.file(db);