Files
ruff/crates/ruff_python_semantic
Brent Westbrook fd09d37007 Fix panic on access to definitions after analyzing definitions (#23588)
Summary
--

This PR fixes #23587 by removing this `std::mem::take` call:


https://github.com/astral-sh/ruff/blob/a62ba8c6e2bac0b899d90fd30a1b26c07aac44bb/crates/ruff_linter/src/checkers/ast/analyze/definitions.rs#L120

This was previously moving the `Definitions` out of the `Checker` and
causing
this operation to panic if the definitions were accessed in a later
analysis
phase:


https://github.com/astral-sh/ruff/blob/a62ba8c6e2bac0b899d90fd30a1b26c07aac44bb/crates/ruff_linter/src/checkers/ast/analyze/definitions.rs#L120

which was apparently never done before `PLR1712` was added.

I don't see any reason why this really needed to be a move as it only
took a
couple of lifetimes to handle it with borrowing, so this seems like the
easiest
fix.

I also changed the indexing operation to a `get` call (with a
`debug_assert`)
since the method already returns an `Option`, but doing that alone would
prevent
`PLR1712` from firing in the module scope.

Test Plan
--

A new test based on the issue that also covers the module scope
mentioned above
2026-02-26 14:19:32 -05:00
..
2026-01-02 19:58:15 +00:00