ruff
71541d47 - [ty] Infer empty collection constructors from later uses (#26389)

Commit
127 days ago
[ty] Infer empty collection constructors from later uses (#26389) ## Summary Unannotated collection literals participate in full-scope bidirectional inference, but empty constructor calls (`list()`, `set()`, and `dict()`) did not. For example, we previously accepted this function because `result` remained `set[Unknown]`: ```python def make_set() -> set[str]: result = set() result.add(1) reveal_type(result) # revealed: set[int | str] return result # error: [invalid-return-type] ``` This PR treats bare, zero-argument `list()`, `set()`, and `dict()` assignment values as collection initializers in the semantic index and reuses the existing collection-use constraint inference. (For now, we don't support aliased or attribute-accessed calls.) Closes https://github.com/astral-sh/ty/issues/3573.
Author
Parents
Loading