[ty] Limit argument expansion size for overload call evaluation by dhruvmanila · Pull Request #20041 · astral-sh/ruff (original) (raw)

@dhruvmanila

@dhruvmanila added the ty

Multi-file analysis & type inference

label

Aug 22, 2025

MichaReiser

@dhruvmanila

@dhruvmanila

dhruvmanila

@dhruvmanila

@dhruvmanila

@dhruvmanila dhruvmanila deleted the dhruv/limit-argument-expansion-size branch

August 25, 2025 09:43

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

Sep 9, 2025

@dhruvmanila @second-ed

…al-sh#20041)

Summary

This PR limits the argument type expansion size for an overload call evaluation to 512.

The limit chosen is arbitrary but I've taken the 256 limit from Pyright into account and bumped it x2 to start with.

Initially, I actually started out by trying to refactor the entire argument type expansion to be lazy. Currently, expanding a single argument at any position eagerly creates the combination (argument lists) and returns that (Vec<CallArguments>) but I thought we could make it lazier by converting the return type of expand from Iterator<Item = Vec<CallArguments>> to Iterator<Item = Iterator<Item = CallArguments>> but that's proving to be difficult to implement mainly because we need to maintain the previous expansion to generate the next expansion which is the main reason to use std::iter::successors in the first place.

Another approach would be to eagerly expand all the argument types and then use the combinations from itertools to generate the combinations but we would need to find the "boundary" between arguments lists produced from expanding argument at position 1 and position 2 because that's important for the algorithm.

Closes: astral-sh/ty#868

Test Plan

Add test case to demonstrate the limit along with the diagnostic snapshot stating that the limit has been reached.

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 }})