ruff
5dabb443 - [ty] Use reaching definitions for redundant-condition exemptions (#28788)

Commit
37 days ago
[ty] Use reaching definitions for redundant-condition exemptions (#28788) Redundant-condition exemptions currently consider assignments that do not reach the condition. For example, `value = 1; if value: ...` can lose its `redundant-condition-strict` diagnostic merely because `value = sys.platform` appears later in the function. An overwritten platform-dependent value can suppress the diagnostic in the same way. Use the existing place-load resolution to follow the definitions that reach each read, including reads through aliases and definite attribute assignments. Preserve environment-dependent assignment guards, lazy closure/global reads, and conservative member lookup when an attribute has no definite assignment at the use. Cache shared provenance and guard summaries so repeated conditions do not repeatedly scan all assignments. ## Test plan Add mdtests covering later and overwritten assignments, aliases, separate and merged branches, assignment guards versus guards around a use, eager and lazy scopes, global/nonlocal overwrites, comprehension assignments, star imports, augmented assignments, and definite versus implicit attribute bindings. Preserve annotation hints for captured tuple variables and extend the existing query-reuse regression test to cover repeated closure reads. ## Ecosystem report For head `6487736580b552faad10bb382e3e088ee28af1f8`, all four added diagnostics are expected: parso's annotation omits `None`, schema_salad disables the tested branch, spack already asserts the tested value is `None`, and steam.py tests an always-truthy TypedDict. Each change was reproduced and minimized against the exact CI revisions. CI is green with no unresolved ecosystem concerns. [Full report and minimized examples](https://github.com/astral-sh/ruff/pull/28788#issuecomment-5782857703).
Author
Parents
Loading