ruff/crates
TomerBin 9910ec700c
[ty] Better control flow for boolean expressions that are inside if (#18010)
## 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>
2025-05-16 11:59:21 +00:00
..
ruff Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_annotate_snippets Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_benchmark Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_cache Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_db Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_dev Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_diagnostics Inline DiagnosticKind into other diagnostic types (#18074) 2025-05-15 10:27:21 -04:00
ruff_formatter Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_graph Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_index Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_linter Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_macros Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_notebook Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_options_metadata [ty] Document configuration schema (#17950) 2025-05-09 10:47:45 +02:00
ruff_python_ast Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_python_ast_integration_tests Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_python_codegen Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_python_formatter Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_python_index Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_python_literal Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_python_parser Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_python_resolver Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_python_semantic Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_python_stdlib Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_python_trivia Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_python_trivia_integration_tests Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_server Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_source_file Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_text_size Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_wasm Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_workspace Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ty Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ty_ide Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ty_project Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ty_python_semantic [ty] Better control flow for boolean expressions that are inside if (#18010) 2025-05-16 11:59:21 +00:00
ty_server Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ty_test Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ty_vendored Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ty_wasm Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00