mirror of
https://github.com/astral-sh/ruff.git
synced 2026-12-03 21:32:26 +08:00
## Summary
At the end of this `if`, ty merges the narrowing and reachability
constraints for `number`, then repeats the same work for `text`. Both
parameters reach the join through the same paths, and each keeps its
original binding and declaration in both branches.
```python
def pair(flag: bool, number: int, text: str):
if flag:
result = (number, text)
else:
result = (text, number)
reveal_type(number) # int
reveal_type(text) # str
return result
```
We now remember the last merge at the join for which both branches agree
on a single binding and a single declaration. If another name has the
same input constraints and pending paths in both branches, we reuse the
merged constraints and keep that name’s own definitions. We also inline
the simple cases and cache lookups for constraint `AND` and `OR`
operations.
(We used 2.11% fewer instructions for a cold check of PyTorch.
Instruction counts also fell on Black (3.31%) and Jinja (0.90%).)
---------
Co-authored-by: Charlie Marsh <charliemarsh@openai.com>
ty_python_core
This crate is an internal component of Ruff. The Rust API exposed here is unstable and will have frequent breaking changes.
This version (0.0.20) is a component of Ruff 0.17.3. The source can be found here.
See Ruff's crate versioning policy for details on versioning.