Track fix isolation in unnecessary-pass (#7715)

## Summary

This wasn't necessary in the past, since we _only_ applied this rule to
bodies that contained two statements, one of which was a `pass`. Now
that it applies to any `pass` in a block with multiple statements, we
can run into situations in which we remove both passes, and so need to
apply the fixes in isolation.

See:
https://github.com/astral-sh/ruff/issues/7455#issuecomment-1741107573.
This commit is contained in:
Charlie Marsh 2023-09-29 13:23:04 -04:00 committed by GitHub
parent 974262ad2c
commit 253fbb665f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 140 additions and 14 deletions

View file

@ -887,11 +887,9 @@ impl<'a> SemanticModel<'a> {
.filter(|id| self.nodes[*id].is_statement())
}
/// Return the [`NodeId`] of the current [`Stmt`].
pub fn current_statement_id(&self) -> NodeId {
self.current_statement_ids()
.next()
.expect("No current statement")
/// Return the [`NodeId`] of the current [`Stmt`], if any.
pub fn current_statement_id(&self) -> Option<NodeId> {
self.current_statement_ids().next()
}
/// Return the [`NodeId`] of the current [`Stmt`] parent, if any.