ruff
0ea258f0 - [ty] Lazily build TypeVar accumulations (#24782)

Commit
87 days ago
[ty] Lazily build TypeVar accumulations (#24782) ## Summary Given a generic specialization, we were rebuilding the constraints after every argument, rather than all-at-once. E.g., for: ```python def combine[T](a: T, b: T, c: T, d: T) -> T: return a combine(("name", 1), ("id", 2), ("flag", True), ("size", 4)) ``` Each argument constrains the same type variable `T`: ```python T = tuple[Literal["name"], Literal[1]] T = tuple[Literal["id"], Literal[2]] T = tuple[Literal["flag"], Literal[True]] T = tuple[Literal["size"], Literal[4]] ``` On main, we then compute (roughly): ``` T = A T = union(A, B) T = union(union(A, B), C) T = union(union(A, B, C), D) ``` Now, we create a builder and construct at the end. This has a significant impact on functions with many arguments, but also reduces memory on real-world projects, which is great.
Author
Parents
Loading