mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 04:45:01 +00:00
![]() This example from @sharkdp shows how terminal statements can appear in statically known branches: https://github.com/astral-sh/ruff/pull/15676#issuecomment-2618809716 ```py def _(cond: bool): x = "a" if cond: x = "b" if True: return reveal_type(x) # revealed: "a", "b"; should be "a" ``` We now use visibility constraints to track reachability, which allows us to model this correctly. There are two related changes as a result: - New bindings are not assumed to be visible; they inherit the current "scope start" visibility, which effectively means that new bindings are visible if/when the current flow is reachable - When simplifying visibility constraints after branching control flow, we only simplify if none of the intervening branches included a terminal statement. That is, earlier unaffected bindings are only _actually_ unaffected if all branches make it to the merge point. |
||
---|---|---|
.. | ||
basic.md | ||
control_flow.md | ||
except_star.md | ||
invalid_syntax.md |