mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-14 12:29:11 +00:00
Format PatternMatchSingleton
(#6741)
This commit is contained in:
parent
fa32cd9b6f
commit
0f9ccfcad9
4 changed files with 63 additions and 8 deletions
|
@ -141,3 +141,20 @@ match pattern_comments:
|
||||||
no_comments
|
no_comments
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
match pattern_singleton:
|
||||||
|
case (
|
||||||
|
# leading 1
|
||||||
|
# leading 2
|
||||||
|
None # trailing
|
||||||
|
# trailing own 1
|
||||||
|
# trailing own 2
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
case (
|
||||||
|
True # trailing
|
||||||
|
):
|
||||||
|
...
|
||||||
|
case False:
|
||||||
|
...
|
||||||
|
|
|
@ -1,13 +1,18 @@
|
||||||
use ruff_formatter::{write, Buffer, FormatResult};
|
use crate::prelude::*;
|
||||||
use ruff_python_ast::PatternMatchSingleton;
|
use ruff_python_ast::{Constant, PatternMatchSingleton};
|
||||||
|
|
||||||
use crate::{not_yet_implemented_custom_text, FormatNodeRule, PyFormatter};
|
use crate::{FormatNodeRule, PyFormatter};
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct FormatPatternMatchSingleton;
|
pub struct FormatPatternMatchSingleton;
|
||||||
|
|
||||||
impl FormatNodeRule<PatternMatchSingleton> for FormatPatternMatchSingleton {
|
impl FormatNodeRule<PatternMatchSingleton> for FormatPatternMatchSingleton {
|
||||||
fn fmt_fields(&self, item: &PatternMatchSingleton, f: &mut PyFormatter) -> FormatResult<()> {
|
fn fmt_fields(&self, item: &PatternMatchSingleton, f: &mut PyFormatter) -> FormatResult<()> {
|
||||||
write!(f, [not_yet_implemented_custom_text("None", item)])
|
match item.value {
|
||||||
|
Constant::None => text("None").fmt(f),
|
||||||
|
Constant::Bool(true) => text("True").fmt(f),
|
||||||
|
Constant::Bool(false) => text("False").fmt(f),
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -292,7 +292,7 @@ match x:
|
||||||
y = 0
|
y = 0
|
||||||
# case black_test_patma_232
|
# case black_test_patma_232
|
||||||
match x:
|
match x:
|
||||||
@@ -108,37 +108,37 @@
|
@@ -108,7 +108,7 @@
|
||||||
y = 0
|
y = 0
|
||||||
# case black_test_patma_058
|
# case black_test_patma_058
|
||||||
match x:
|
match x:
|
||||||
|
@ -301,8 +301,7 @@ match x:
|
||||||
y = 0
|
y = 0
|
||||||
# case black_test_patma_233
|
# case black_test_patma_233
|
||||||
match x:
|
match x:
|
||||||
- case False:
|
@@ -116,29 +116,29 @@
|
||||||
+ case None:
|
|
||||||
y = 0
|
y = 0
|
||||||
# case black_test_patma_078
|
# case black_test_patma_078
|
||||||
match x:
|
match x:
|
||||||
|
@ -460,7 +459,7 @@ match x:
|
||||||
y = 0
|
y = 0
|
||||||
# case black_test_patma_233
|
# case black_test_patma_233
|
||||||
match x:
|
match x:
|
||||||
case None:
|
case False:
|
||||||
y = 0
|
y = 0
|
||||||
# case black_test_patma_078
|
# case black_test_patma_078
|
||||||
match x:
|
match x:
|
||||||
|
|
|
@ -147,6 +147,23 @@ match pattern_comments:
|
||||||
no_comments
|
no_comments
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
match pattern_singleton:
|
||||||
|
case (
|
||||||
|
# leading 1
|
||||||
|
# leading 2
|
||||||
|
None # trailing
|
||||||
|
# trailing own 1
|
||||||
|
# trailing own 2
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
case (
|
||||||
|
True # trailing
|
||||||
|
):
|
||||||
|
...
|
||||||
|
case False:
|
||||||
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
## Output
|
## Output
|
||||||
|
@ -285,6 +302,23 @@ match pattern_comments:
|
||||||
match pattern_comments:
|
match pattern_comments:
|
||||||
case (x as NOT_YET_IMPLEMENTED_PatternMatchAs):
|
case (x as NOT_YET_IMPLEMENTED_PatternMatchAs):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
match pattern_singleton:
|
||||||
|
case (
|
||||||
|
# leading 1
|
||||||
|
# leading 2
|
||||||
|
None # trailing
|
||||||
|
# trailing own 1
|
||||||
|
# trailing own 2
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
case (
|
||||||
|
True # trailing
|
||||||
|
):
|
||||||
|
...
|
||||||
|
case False:
|
||||||
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue