[ty] Avoid unnecessary argument type expansion by dhruvmanila · Pull Request #19999 · astral-sh/ruff (original) (raw)

@dhruvmanila

@dhruvmanila added performance

Potential performance improvement

ty

Multi-file analysis & type inference

labels

Aug 20, 2025

@dhruvmanila

@dhruvmanila

dhruvmanila

@dhruvmanila

@dhruvmanila

MichaReiser

@dhruvmanila

@dhruvmanila dhruvmanila deleted the dhruv/avoid-argument-type-expansion branch

August 21, 2025 06:13

dcreager added a commit that referenced this pull request

Aug 21, 2025

@dcreager

second-ed pushed a commit to second-ed/ruff that referenced this pull request

Sep 9, 2025

@dhruvmanila @second-ed

Summary

Part of: astral-sh/ty#868

This PR adds a heuristic to avoid argument type expansion if it's going to eventually lead to no matching overload.

This is done by checking whether the non-expandable argument types are assignable to the corresponding annotated parameter type. If one of them is not assignable to all of the remaining overloads, then argument type expansion isn't going to help.

Test Plan

Add mdtest that would otherwise take a long time because of the number of arguments that it would need to expand (30).

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})