mirror of
https://github.com/astral-sh/ruff.git
synced 2026-10-28 10:45:37 +08:00
## Summary Ty could panic on `assert predicate` inside a loop where `predicate` starts as a lambda and a later iteration rebinds it to a class. When cycle recovery added the class to the operand type, ty looked up its metaclass to determine its truthiness. That lookup could introduce a new inference cycle while Salsa was recovering the first one. Reachability now evaluates the predicate from the operand types that expression inference has already normalized. Outside loops, it caches the result so repeated walks of the same condition can reuse it. Inside a loop, a condition can depend on an assignment it guards, so the caller reads the inferred operands directly. Expression inference no longer stores predicate truthiness or recomputes it during recovery. The 163-project ecosystem run produced identical diagnostics. Checking isort took 291 ms, up from 248 ms on the base revision, which gives back some of the speedup from #29706. The average timing factor across projects was 1.02×. CodSpeed found no significant changes among the 214 benchmarks it compared. [Ecosystem diff](https://dqhfo45wdv0ek.cloudfront.net/ruff/pull-requests/29759/ty-ecosystem/40467940782/1/diff.html) · [Timings](https://dqhfo45wdv0ek.cloudfront.net/ruff/pull-requests/29759/ty-ecosystem/40467940782/1/timing.html) · [CodSpeed](https://github.com/astral-sh/ruff/pull/29759#issuecomment-6435864937) Closes https://github.com/astral-sh/ty/issues/4834.
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.