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

Code before:
                                    db,
                                    prefix_parameters
                                        .iter()
                                        .map(|param| {
                                            param.apply_type_mapping_impl(
                                                db,
                                                type_mapping,
                                                tcx,
                                                visitor,
                                            )
                                        })
                                        .chain(signature.parameters().iter().cloned()),
                                )
                            },
                            return_ty: self_signature.return_ty.map(|ty| {
                                ty.apply_type_mapping_impl(db, type_mapping, tcx, visitor)
                            }),
                        }),
                    ))
                }
                _ => None,
            }
        }

        match type_mapping {
            TypeMapping::Specialization(specialization) => {
                Self::from_overloads(self.overloads.iter().flat_map(|signature| {
                    if let Some((prefix, paramspec)) =
                        signature.parameters.find_paramspec_from_args_kwargs(db)
                        && let Some(value) = specialization.get(db, paramspec)
                        && let Some(result) = try_apply_type_mapping_for_paramspec(
                            db,
                            signature,
                            prefix,
                            value,
                            type_mapping,
                            tcx,
                            visitor,
                        )
                    {
                        result.overloads
                    } else {
                        smallvec_inline![signature.apply_type_mapping_impl(
                            db,
                            type_mapping,
                            tcx,
                            visitor
                        )]
                    }
                }))
            }

Review comment (suggestion):
Not in scope for this PR, but I want to take a quick stab at seeing if we can remove the redundancy between `Specialization` and `PartialSpecialization`. This is getting silly that you/we have to copy-paste this much!

Code after:
                            } else {
                                Parameters::new(
                                    db,
                                    prefix_parameters
                                        .iter()
                                        .map(|param| {
                                            param.apply_type_mapping_impl(
                                                db,
                                                type_mapping,
                                                tcx,
                                                visitor,
                                            )
                                        })
                                        .chain(signature.parameters().iter().cloned()),
                                )
                            },
                            return_ty: self_signature.return_ty.map(|ty| {
                                ty.apply_type_mapping_impl(db, type_mapping, tcx, visitor)
                            }),
                        }),
                    ))
                }
                _ => None,
            }
        }

        if let TypeMapping::ApplySpecialization(specialization) = type_mapping {
            Self::from_overloads(self.overloads.iter().flat_map(|signature| {
                if let Some((prefix, paramspec)) =
                    signature.parameters.find_paramspec_from_args_kwargs(db)
                    && let Some(value) = specialization.get(db, paramspec)
                    && let Some(result) = try_apply_type_mapping_for_paramspec(
                        db,
                        signature,
                        prefix,
                        value,
                        type_mapping,
                        tcx,
                        visitor,
                    )
                {
                    result.overloads
                } else {
                    smallvec_inline![signature.apply_type_mapping_impl(
                        db,
                        type_mapping,
                        tcx,
                        visitor
                    )]
                }
            }))