mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28:24 +00:00
![]() ## Summary With this PR we now detect that x is always defined in `use`: ```py if flag and (x := number): use(x) ``` When outside if, it's still detected as possibly not defined ```py flag and (x := number) # error: [possibly-unresolved-reference] use(x) ``` In order to achieve that, I had to find a way to get access to the flow-snapshots of the boolean expression when analyzing the flow of the if statement. I did it by special casing the visitor of boolean expression to return flow control information, exporting two snapshots - `maybe_short_circuit` and `no_short_circuit`. When indexing boolean expression itself we must assume all possible flows, but when it's inside if statement, we can be smarter than that. ## Test Plan Fixed existing and added new mdtests. I went through some of mypy primer results and they look fine --------- Co-authored-by: Carl Meyer <carl@astral.sh> |
||
---|---|---|
.. | ||
mdtest | ||
primer | ||
README.md |
Markdown files within the mdtest/
subdirectory are tests of type inference and type checking;
executed by the tests/mdtest.rs
integration test.
See crates/ty_test/README.md
for documentation of this test format.