forked from astral-sh/ruff
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
124 additions
and
517 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 31 additions & 9 deletions
40
crates/ruff_python_formatter/src/pattern/pattern_match_class.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,41 @@ | ||
use ruff_formatter::{write, Buffer, FormatResult}; | ||
use ruff_formatter::{write, FormatResult}; | ||
use ruff_python_ast::PatternMatchClass; | ||
|
||
use crate::{not_yet_implemented_custom_text, FormatNodeRule, PyFormatter}; | ||
use crate::expression::parentheses::parenthesized; | ||
use crate::prelude::*; | ||
use crate::{FormatNodeRule, PyFormatter}; | ||
|
||
#[derive(Default)] | ||
pub struct FormatPatternMatchClass; | ||
|
||
impl FormatNodeRule<PatternMatchClass> for FormatPatternMatchClass { | ||
fn fmt_fields(&self, item: &PatternMatchClass, f: &mut PyFormatter) -> FormatResult<()> { | ||
write!( | ||
f, | ||
[not_yet_implemented_custom_text( | ||
"NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0)", | ||
item | ||
)] | ||
) | ||
let PatternMatchClass { | ||
range, | ||
cls, | ||
patterns, | ||
kwd_attrs, | ||
kwd_patterns, | ||
} = item; | ||
|
||
let items = format_with(|f| { | ||
let mut join = f.join_comma_separated(range.end()); | ||
|
||
if !patterns.is_empty() { | ||
join.nodes(patterns.iter()); | ||
} | ||
|
||
if !kwd_attrs.is_empty() { | ||
for (key, value) in kwd_attrs.iter().zip(kwd_patterns.iter()) { | ||
join.entry( | ||
key, | ||
&format_with(|f| write!(f, [key.format(), text("="), value.format()])), | ||
); | ||
} | ||
} | ||
join.finish() | ||
}); | ||
|
||
write!(f, [cls.format(), parenthesized("(", &items, ")")]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.