mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-27 05:44:18 +00:00
Placement refactor (#6034)
## Summary This PR is a refactoring of placement.rs. The code got more consistent, some comments were updated and some dead code was removed or replaced with debug assertions. It also contains a bugfix for the placement of end-of-branch comments with nested bodies inside try statements that occurred when refactoring the nested body loop. ## Test Plan The existing test cases don't change. I added a couple of cases that i think should be tested but weren't, and a regression test for the bugfix
This commit is contained in:
parent
51d8fc1f30
commit
e7f228f781
10 changed files with 383 additions and 352 deletions
|
@ -4390,6 +4390,16 @@ impl AnyNodeRef<'_> {
|
|||
| AnyNodeRef::StmtTryStar(_)
|
||||
)
|
||||
}
|
||||
|
||||
/// In our AST, only some alternative branches are represented as a node. This has historical
|
||||
/// reasons, e.g. we added a node for elif/else in if statements which was not originally
|
||||
/// present in the parser.
|
||||
pub const fn is_alternative_branch_with_node(self) -> bool {
|
||||
matches!(
|
||||
self,
|
||||
AnyNodeRef::ExceptHandlerExceptHandler(_) | AnyNodeRef::ElifElseClause(_)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a ast::ModModule> for AnyNodeRef<'a> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue