ruff
c96297ff - [ty] Avoid inferring a member prefix's type to check whether it is bound (#30057)

Commit
13 days ago
[ty] Avoid inferring a member prefix's type to check whether it is bound (#30057) ## Summary When ty reads `box.value`, it looks for assignments that could narrow the type of `value`. In this example, the parameter shadows the module-level `box`, so the assignment `box.value = 1` tells us nothing about the value inside `read`. ```python from typing import reveal_type class Box: value: int | str box = Box() box.value = 1 def read(box: Box): reveal_type(box.value) # int | str ``` Previously, ty inferred the parameter's type just to establish that `box` was bound in the function. We now skip that inference when a single ordinary definition reaches the read. We can also answer directly when the only entry is unbound. Deletions, synthetic bindings, and multiple reaching definitions still use the full lookup. A cold `ty check` used 0.84% fewer instructions on SymPy and 0.59% fewer on SQLAlchemy, with identical diagnostics on both projects.
Author
Parents
Loading