Call pattern formatting (#6594)

This commit is contained in:
Micha Reiser 2023-08-16 05:01:25 +02:00 committed by GitHub
parent 9bf6713b76
commit 897cce83b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 473 additions and 330 deletions

View file

@ -108,3 +108,36 @@ match long_lines:
bbbbbbbbaaaaaahhhh == 2 bbbbbbbbaaaaaahhhh == 2
): # another comment ): # another comment
pass pass
match pattern_comments:
case (
only_trailing # trailing 1
# trailing 2
# trailing 3
):
pass
match pattern_comments:
case ( # leading
only_leading
):
pass
match pattern_comments:
case (
# leading
leading_and_trailing # trailing 1
# trailing 2
# trailing 3
):
pass
match pattern_comments:
case (
no_comments
):
pass

View file

@ -388,6 +388,7 @@ impl<'a> Comments<'a> {
} }
/// Returns an iterator over the [leading](self#leading-comments) and [trailing comments](self#trailing-comments) of `node`. /// Returns an iterator over the [leading](self#leading-comments) and [trailing comments](self#trailing-comments) of `node`.
#[allow(unused)]
pub(crate) fn leading_trailing_comments<T>( pub(crate) fn leading_trailing_comments<T>(
&self, &self,
node: T, node: T,

View file

@ -152,40 +152,6 @@ pub fn format_node<'a>(
Ok(formatted) Ok(formatted)
} }
pub(crate) struct NotYetImplemented<'a>(AnyNodeRef<'a>);
/// Formats a placeholder for nodes that have not yet been implemented
pub(crate) fn not_yet_implemented<'a, T>(node: T) -> NotYetImplemented<'a>
where
T: Into<AnyNodeRef<'a>>,
{
NotYetImplemented(node.into())
}
impl Format<PyFormatContext<'_>> for NotYetImplemented<'_> {
fn fmt(&self, f: &mut PyFormatter) -> FormatResult<()> {
let text = std::format!("NOT_YET_IMPLEMENTED_{:?}", self.0.kind());
f.write_element(FormatElement::Tag(Tag::StartVerbatim(
tag::VerbatimKind::Verbatim {
length: text.text_len(),
},
)))?;
f.write_element(FormatElement::DynamicText {
text: Box::from(text),
})?;
f.write_element(FormatElement::Tag(Tag::EndVerbatim))?;
f.context()
.comments()
.mark_verbatim_node_comments_formatted(self.0);
Ok(())
}
}
pub(crate) struct NotYetImplementedCustomText<'a> { pub(crate) struct NotYetImplementedCustomText<'a> {
text: &'static str, text: &'static str,
node: AnyNodeRef<'a>, node: AnyNodeRef<'a>,

View file

@ -1,10 +1,12 @@
use ruff_formatter::{write, Buffer, FormatResult}; use ruff_formatter::{format_args, write, Buffer, FormatResult};
use ruff_python_ast::MatchCase; use ruff_python_ast::{MatchCase, Pattern, Ranged};
use ruff_python_trivia::{SimpleTokenKind, SimpleTokenizer};
use ruff_text_size::TextRange;
use crate::comments::{trailing_comments, SourceComment}; use crate::comments::{leading_comments, trailing_comments, SourceComment};
use crate::not_yet_implemented_custom_text; use crate::expression::parentheses::parenthesized;
use crate::prelude::*; use crate::prelude::*;
use crate::{FormatNodeRule, PyFormatter}; use crate::{FormatError, FormatNodeRule, PyFormatter};
#[derive(Default)] #[derive(Default)]
pub struct FormatMatchCase; pub struct FormatMatchCase;
@ -21,24 +23,20 @@ impl FormatNodeRule<MatchCase> for FormatMatchCase {
let comments = f.context().comments().clone(); let comments = f.context().comments().clone();
let dangling_item_comments = comments.dangling_comments(item); let dangling_item_comments = comments.dangling_comments(item);
write!( write!(f, [text("case"), space()])?;
f, let leading_pattern_comments = comments.leading_comments(pattern);
[ if !leading_pattern_comments.is_empty() {
text("case"), parenthesized(
space(), "(",
format_with(|f: &mut PyFormatter| { &format_args![leading_comments(leading_pattern_comments), pattern.format()],
let comments = f.context().comments(); ")",
)
for comment in comments.leading_trailing_comments(pattern) { .fmt(f)?;
// This is a lie, but let's go with it. } else if is_match_case_pattern_parenthesized(item, pattern, f.context())? {
comment.mark_formatted(); parenthesized("(", &pattern.format(), ")").fmt(f)?;
} } else {
pattern.format().fmt(f)?;
// Replace the whole `format_with` with `pattern.format()` once pattern formatting is implemented. }
not_yet_implemented_custom_text("NOT_YET_IMPLEMENTED_Pattern", pattern).fmt(f)
}),
]
)?;
if let Some(guard) = guard { if let Some(guard) = guard {
write!(f, [space(), text("if"), space(), guard.format()])?; write!(f, [space(), text("if"), space(), guard.format()])?;
@ -63,3 +61,33 @@ impl FormatNodeRule<MatchCase> for FormatMatchCase {
Ok(()) Ok(())
} }
} }
fn is_match_case_pattern_parenthesized(
case: &MatchCase,
pattern: &Pattern,
context: &PyFormatContext,
) -> FormatResult<bool> {
let mut tokenizer = SimpleTokenizer::new(
context.source(),
TextRange::new(case.range().start(), pattern.range().start()),
)
.skip_trivia();
let case_keyword = tokenizer.next().ok_or(FormatError::syntax_error(
"Expected a `case` keyword, didn't find any token",
))?;
debug_assert_eq!(
case_keyword.kind(),
SimpleTokenKind::Case,
"Expected `case` keyword but at {case_keyword:?}"
);
match tokenizer.next() {
Some(left_paren) => {
debug_assert_eq!(left_paren.kind(), SimpleTokenKind::LParen);
Ok(true)
}
None => Ok(false),
}
}

View file

@ -1,12 +1,19 @@
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
use ruff_formatter::{write, Buffer, FormatResult}; use ruff_formatter::{write, Buffer, FormatResult};
use ruff_python_ast::PatternMatchAs; use ruff_python_ast::PatternMatchAs;
use crate::{not_yet_implemented_custom_text, FormatNodeRule, PyFormatter};
#[derive(Default)] #[derive(Default)]
pub struct FormatPatternMatchAs; pub struct FormatPatternMatchAs;
impl FormatNodeRule<PatternMatchAs> for FormatPatternMatchAs { impl FormatNodeRule<PatternMatchAs> for FormatPatternMatchAs {
fn fmt_fields(&self, item: &PatternMatchAs, f: &mut PyFormatter) -> FormatResult<()> { fn fmt_fields(&self, item: &PatternMatchAs, f: &mut PyFormatter) -> FormatResult<()> {
write!(f, [not_yet_implemented(item)]) write!(
f,
[not_yet_implemented_custom_text(
"x as NOT_YET_IMPLEMENTED_PatternMatchAs",
item
)]
)
} }
} }

View file

@ -1,12 +1,19 @@
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
use ruff_formatter::{write, Buffer, FormatResult}; use ruff_formatter::{write, Buffer, FormatResult};
use ruff_python_ast::PatternMatchClass; use ruff_python_ast::PatternMatchClass;
use crate::{not_yet_implemented_custom_text, FormatNodeRule, PyFormatter};
#[derive(Default)] #[derive(Default)]
pub struct FormatPatternMatchClass; pub struct FormatPatternMatchClass;
impl FormatNodeRule<PatternMatchClass> for FormatPatternMatchClass { impl FormatNodeRule<PatternMatchClass> for FormatPatternMatchClass {
fn fmt_fields(&self, item: &PatternMatchClass, f: &mut PyFormatter) -> FormatResult<()> { fn fmt_fields(&self, item: &PatternMatchClass, f: &mut PyFormatter) -> FormatResult<()> {
write!(f, [not_yet_implemented(item)]) write!(
f,
[not_yet_implemented_custom_text(
"NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0)",
item
)]
)
} }
} }

View file

@ -1,12 +1,19 @@
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
use ruff_formatter::{write, Buffer, FormatResult}; use ruff_formatter::{write, Buffer, FormatResult};
use ruff_python_ast::PatternMatchMapping; use ruff_python_ast::PatternMatchMapping;
use crate::{not_yet_implemented_custom_text, FormatNodeRule, PyFormatter};
#[derive(Default)] #[derive(Default)]
pub struct FormatPatternMatchMapping; pub struct FormatPatternMatchMapping;
impl FormatNodeRule<PatternMatchMapping> for FormatPatternMatchMapping { impl FormatNodeRule<PatternMatchMapping> for FormatPatternMatchMapping {
fn fmt_fields(&self, item: &PatternMatchMapping, f: &mut PyFormatter) -> FormatResult<()> { fn fmt_fields(&self, item: &PatternMatchMapping, f: &mut PyFormatter) -> FormatResult<()> {
write!(f, [not_yet_implemented(item)]) write!(
f,
[not_yet_implemented_custom_text(
"{\"NOT_YET_IMPLEMENTED_PatternMatchMapping\": _, 2: _}",
item
)]
)
} }
} }

View file

@ -1,12 +1,19 @@
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
use ruff_formatter::{write, Buffer, FormatResult}; use ruff_formatter::{write, Buffer, FormatResult};
use ruff_python_ast::PatternMatchOr; use ruff_python_ast::PatternMatchOr;
use crate::{not_yet_implemented_custom_text, FormatNodeRule, PyFormatter};
#[derive(Default)] #[derive(Default)]
pub struct FormatPatternMatchOr; pub struct FormatPatternMatchOr;
impl FormatNodeRule<PatternMatchOr> for FormatPatternMatchOr { impl FormatNodeRule<PatternMatchOr> for FormatPatternMatchOr {
fn fmt_fields(&self, item: &PatternMatchOr, f: &mut PyFormatter) -> FormatResult<()> { fn fmt_fields(&self, item: &PatternMatchOr, f: &mut PyFormatter) -> FormatResult<()> {
write!(f, [not_yet_implemented(item)]) write!(
f,
[not_yet_implemented_custom_text(
"NOT_YET_IMPLEMENTED_PatternMatchOf | (y)",
item
)]
)
} }
} }

View file

@ -1,12 +1,19 @@
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
use ruff_formatter::{write, Buffer, FormatResult}; use ruff_formatter::{write, Buffer, FormatResult};
use ruff_python_ast::PatternMatchSequence; use ruff_python_ast::PatternMatchSequence;
use crate::{not_yet_implemented_custom_text, FormatNodeRule, PyFormatter};
#[derive(Default)] #[derive(Default)]
pub struct FormatPatternMatchSequence; pub struct FormatPatternMatchSequence;
impl FormatNodeRule<PatternMatchSequence> for FormatPatternMatchSequence { impl FormatNodeRule<PatternMatchSequence> for FormatPatternMatchSequence {
fn fmt_fields(&self, item: &PatternMatchSequence, f: &mut PyFormatter) -> FormatResult<()> { fn fmt_fields(&self, item: &PatternMatchSequence, f: &mut PyFormatter) -> FormatResult<()> {
write!(f, [not_yet_implemented(item)]) write!(
f,
[not_yet_implemented_custom_text(
"[NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]",
item
)]
)
} }
} }

View file

@ -1,12 +1,13 @@
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
use ruff_formatter::{write, Buffer, FormatResult}; use ruff_formatter::{write, Buffer, FormatResult};
use ruff_python_ast::PatternMatchSingleton; use ruff_python_ast::PatternMatchSingleton;
use crate::{not_yet_implemented_custom_text, 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(item)]) write!(f, [not_yet_implemented_custom_text("None", item)])
} }
} }

View file

@ -1,12 +1,19 @@
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
use ruff_formatter::{write, Buffer, FormatResult}; use ruff_formatter::{write, Buffer, FormatResult};
use ruff_python_ast::PatternMatchStar; use ruff_python_ast::PatternMatchStar;
use crate::{not_yet_implemented_custom_text, FormatNodeRule, PyFormatter};
#[derive(Default)] #[derive(Default)]
pub struct FormatPatternMatchStar; pub struct FormatPatternMatchStar;
impl FormatNodeRule<PatternMatchStar> for FormatPatternMatchStar { impl FormatNodeRule<PatternMatchStar> for FormatPatternMatchStar {
fn fmt_fields(&self, item: &PatternMatchStar, f: &mut PyFormatter) -> FormatResult<()> { fn fmt_fields(&self, item: &PatternMatchStar, f: &mut PyFormatter) -> FormatResult<()> {
write!(f, [not_yet_implemented(item)]) write!(
f,
[not_yet_implemented_custom_text(
"*NOT_YET_IMPLEMENTED_PatternMatchStar",
item
)]
)
} }
} }

View file

@ -1,14 +1,19 @@
use ruff_formatter::{write, Buffer, FormatResult};
use ruff_python_ast::PatternMatchValue; use ruff_python_ast::PatternMatchValue;
use ruff_formatter::{write, Buffer, FormatResult}; use crate::{not_yet_implemented_custom_text, FormatNodeRule, PyFormatter};
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
#[derive(Default)] #[derive(Default)]
pub struct FormatPatternMatchValue; pub struct FormatPatternMatchValue;
impl FormatNodeRule<PatternMatchValue> for FormatPatternMatchValue { impl FormatNodeRule<PatternMatchValue> for FormatPatternMatchValue {
fn fmt_fields(&self, item: &PatternMatchValue, f: &mut PyFormatter) -> FormatResult<()> { fn fmt_fields(&self, item: &PatternMatchValue, f: &mut PyFormatter) -> FormatResult<()> {
write!(f, [not_yet_implemented(item)]) write!(
f,
[not_yet_implemented_custom_text(
"\"NOT_YET_IMPLEMENTED_PatternMatchValue\"",
item
)]
)
} }
} }

View file

@ -51,11 +51,11 @@ impl FormatNodeRule<StmtMatch> for FormatStmtMatch {
write!( write!(
f, f,
[block_indent(&format_args!( [block_indent(&format_args!(
&leading_alternate_branch_comments( leading_alternate_branch_comments(
comments.leading_comments(case), comments.leading_comments(case),
last_case.body.last(), last_case.body.last(),
), ),
&case.format() case.format()
))] ))]
)?; )?;
last_case = case; last_case = case;

View file

@ -156,191 +156,190 @@ match x:
```diff ```diff
--- Black --- Black
+++ Ruff +++ Ruff
@@ -2,143 +2,143 @@ @@ -2,105 +2,105 @@
# case black_test_patma_098 # case black_test_patma_098
match x: match x:
- case -0j: - case -0j:
+ case NOT_YET_IMPLEMENTED_Pattern: + case "NOT_YET_IMPLEMENTED_PatternMatchValue":
y = 0 y = 0
# case black_test_patma_142 # case black_test_patma_142
match x: match x:
- case bytes(z): - case bytes(z):
+ case NOT_YET_IMPLEMENTED_Pattern: + case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
y = 0 y = 0
# case black_test_patma_073 # case black_test_patma_073
match x: match x:
- case 0 if 0: - case 0 if 0:
+ case NOT_YET_IMPLEMENTED_Pattern if 0: + case "NOT_YET_IMPLEMENTED_PatternMatchValue" if 0:
y = 0 y = 0
- case 0 if 1: - case 0 if 1:
+ case NOT_YET_IMPLEMENTED_Pattern if 1: + case "NOT_YET_IMPLEMENTED_PatternMatchValue" if 1:
y = 1 y = 1
# case black_test_patma_006 # case black_test_patma_006
match 3: match 3:
- case 0 | 1 | 2 | 3: - case 0 | 1 | 2 | 3:
+ case NOT_YET_IMPLEMENTED_Pattern: + case NOT_YET_IMPLEMENTED_PatternMatchOf | (y):
x = True x = True
# case black_test_patma_049 # case black_test_patma_049
match x: match x:
- case [0, 1] | [1, 0]: - case [0, 1] | [1, 0]:
+ case NOT_YET_IMPLEMENTED_Pattern: + case NOT_YET_IMPLEMENTED_PatternMatchOf | (y):
y = 0 y = 0
# case black_check_sequence_then_mapping # case black_check_sequence_then_mapping
match x: match x:
- case [*_]: - case [*_]:
+ case NOT_YET_IMPLEMENTED_Pattern: + case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
return "seq" return "seq"
- case {}: - case {}:
+ case NOT_YET_IMPLEMENTED_Pattern: + case {"NOT_YET_IMPLEMENTED_PatternMatchMapping": _, 2: _}:
return "map" return "map"
# case black_test_patma_035 # case black_test_patma_035
match x: match x:
- case {0: [1, 2, {}]}: - case {0: [1, 2, {}]}:
+ case NOT_YET_IMPLEMENTED_Pattern: + case {"NOT_YET_IMPLEMENTED_PatternMatchMapping": _, 2: _}:
y = 0 y = 0
- case {0: [1, 2, {}] | True} | {1: [[]]} | {0: [1, 2, {}]} | [] | "X" | {}: - case {0: [1, 2, {}] | True} | {1: [[]]} | {0: [1, 2, {}]} | [] | "X" | {}:
+ case NOT_YET_IMPLEMENTED_Pattern: + case NOT_YET_IMPLEMENTED_PatternMatchOf | (y):
y = 1 y = 1
- case []: - case []:
+ case NOT_YET_IMPLEMENTED_Pattern: + case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
y = 2 y = 2
# case black_test_patma_107 # case black_test_patma_107
match x: match x:
- case 0.25 + 1.75j: - case 0.25 + 1.75j:
+ case NOT_YET_IMPLEMENTED_Pattern: + case "NOT_YET_IMPLEMENTED_PatternMatchValue":
y = 0 y = 0
# case black_test_patma_097 # case black_test_patma_097
match x: match x:
- case -0j: - case -0j:
+ case NOT_YET_IMPLEMENTED_Pattern: + case "NOT_YET_IMPLEMENTED_PatternMatchValue":
y = 0 y = 0
# case black_test_patma_007 # case black_test_patma_007
match 4: match 4:
- case 0 | 1 | 2 | 3: - case 0 | 1 | 2 | 3:
+ case NOT_YET_IMPLEMENTED_Pattern: + case NOT_YET_IMPLEMENTED_PatternMatchOf | (y):
x = True x = True
# case black_test_patma_154 # case black_test_patma_154
match x: match x:
- case 0 if x: - case 0 if x:
+ case NOT_YET_IMPLEMENTED_Pattern if x: + case "NOT_YET_IMPLEMENTED_PatternMatchValue" if x:
y = 0 y = 0
# case black_test_patma_134 # case black_test_patma_134
match x: match x:
- case {1: 0}: - case {1: 0}:
+ case NOT_YET_IMPLEMENTED_Pattern: + case {"NOT_YET_IMPLEMENTED_PatternMatchMapping": _, 2: _}:
y = 0 y = 0
- case {0: 0}: - case {0: 0}:
+ case NOT_YET_IMPLEMENTED_Pattern: + case {"NOT_YET_IMPLEMENTED_PatternMatchMapping": _, 2: _}:
y = 1 y = 1
- case {**z}: - case {**z}:
+ case NOT_YET_IMPLEMENTED_Pattern: + case {"NOT_YET_IMPLEMENTED_PatternMatchMapping": _, 2: _}:
y = 2 y = 2
# case black_test_patma_185 # case black_test_patma_185
match Seq(): match Seq():
- case [*_]: - case [*_]:
+ case NOT_YET_IMPLEMENTED_Pattern: + case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
y = 0 y = 0
# case black_test_patma_063 # case black_test_patma_063
match x: match x:
- case 1: - case 1:
+ case NOT_YET_IMPLEMENTED_Pattern: + case "NOT_YET_IMPLEMENTED_PatternMatchValue":
y = 0 y = 0
- case 1: - case 1:
+ case NOT_YET_IMPLEMENTED_Pattern: + case "NOT_YET_IMPLEMENTED_PatternMatchValue":
y = 1 y = 1
# case black_test_patma_248 # case black_test_patma_248
match x: match x:
- case {"foo": bar}: - case {"foo": bar}:
+ case NOT_YET_IMPLEMENTED_Pattern: + case {"NOT_YET_IMPLEMENTED_PatternMatchMapping": _, 2: _}:
y = bar y = bar
# case black_test_patma_019 # case black_test_patma_019
match (0, 1, 2): match (0, 1, 2):
- case [0, 1, *x, 2]: - case [0, 1, *x, 2]:
+ case NOT_YET_IMPLEMENTED_Pattern: + case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
y = 0 y = 0
# case black_test_patma_052 # case black_test_patma_052
match x: match x:
- case [0]: - case [0]:
+ case NOT_YET_IMPLEMENTED_Pattern: + case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
y = 0 y = 0
- case [1, 0] if (x := x[:0]): - case [1, 0] if (x := x[:0]):
+ case NOT_YET_IMPLEMENTED_Pattern if (x := x[:0]): + case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2] if (x := x[:0]):
y = 1 y = 1
- case [1, 0]: - case [1, 0]:
+ case NOT_YET_IMPLEMENTED_Pattern: + case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
y = 2 y = 2
# case black_test_patma_191 # case black_test_patma_191
match w: match w:
- case [x, y, *_]: - case [x, y, *_]:
+ case NOT_YET_IMPLEMENTED_Pattern: + case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
z = 0 z = 0
# case black_test_patma_110 # case black_test_patma_110
match x: match x:
- case -0.25 - 1.75j: - case -0.25 - 1.75j:
+ case NOT_YET_IMPLEMENTED_Pattern: + case "NOT_YET_IMPLEMENTED_PatternMatchValue":
y = 0 y = 0
# case black_test_patma_151 # case black_test_patma_151
match (x,): match (x,):
- case [y]: - case [y]:
+ case NOT_YET_IMPLEMENTED_Pattern: + case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
z = 0 z = 0
# case black_test_patma_114 # case black_test_patma_114
match x: match x:
- case A.B.C.D: - case A.B.C.D:
+ case NOT_YET_IMPLEMENTED_Pattern: + case "NOT_YET_IMPLEMENTED_PatternMatchValue":
y = 0 y = 0
# case black_test_patma_232 # case black_test_patma_232
match x: match x:
- case None: @@ -108,37 +108,37 @@
+ case NOT_YET_IMPLEMENTED_Pattern:
y = 0 y = 0
# case black_test_patma_058 # case black_test_patma_058
match x: match x:
- case 0: - case 0:
+ case NOT_YET_IMPLEMENTED_Pattern: + case "NOT_YET_IMPLEMENTED_PatternMatchValue":
y = 0 y = 0
# case black_test_patma_233 # case black_test_patma_233
match x: match x:
- case False: - case False:
+ case NOT_YET_IMPLEMENTED_Pattern: + case None:
y = 0 y = 0
# case black_test_patma_078 # case black_test_patma_078
match x: match x:
- case []: - case []:
+ case NOT_YET_IMPLEMENTED_Pattern: + case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
y = 0 y = 0
- case [""]: - case [""]:
+ case NOT_YET_IMPLEMENTED_Pattern: + case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
y = 1 y = 1
- case "": - case "":
+ case NOT_YET_IMPLEMENTED_Pattern: + case "NOT_YET_IMPLEMENTED_PatternMatchValue":
y = 2 y = 2
# case black_test_patma_156 # case black_test_patma_156
match x: match x:
- case z: - case z:
+ case NOT_YET_IMPLEMENTED_Pattern: + case x as NOT_YET_IMPLEMENTED_PatternMatchAs:
y = 0 y = 0
# case black_test_patma_189 # case black_test_patma_189
match w: match w:
- case [x, y, *rest]: - case [x, y, *rest]:
+ case NOT_YET_IMPLEMENTED_Pattern: + case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
z = 0 z = 0
# case black_test_patma_042 # case black_test_patma_042
match x: match x:
- case (0 as z) | (1 as z) | (2 as z) if z == x % 2: - case (0 as z) | (1 as z) | (2 as z) if z == x % 2:
+ case NOT_YET_IMPLEMENTED_Pattern if z == x % 2: + case NOT_YET_IMPLEMENTED_PatternMatchOf | (y) if z == x % 2:
y = 0 y = 0
# case black_test_patma_034 # case black_test_patma_034
match x: match x:
- case {0: [1, 2, {}]}: - case {0: [1, 2, {}]}:
+ case NOT_YET_IMPLEMENTED_Pattern: + case {"NOT_YET_IMPLEMENTED_PatternMatchMapping": _, 2: _}:
y = 0 y = 0
- case {0: [1, 2, {}] | False} | {1: [[]]} | {0: [1, 2, {}]} | [] | "X" | {}: - case {0: [1, 2, {}] | False} | {1: [[]]} | {0: [1, 2, {}]} | [] | "X" | {}:
+ case NOT_YET_IMPLEMENTED_Pattern: + case NOT_YET_IMPLEMENTED_PatternMatchOf | (y):
y = 1 y = 1
- case []: - case []:
+ case NOT_YET_IMPLEMENTED_Pattern: + case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
y = 2 y = 2
``` ```
@ -351,145 +350,145 @@ match x:
# case black_test_patma_098 # case black_test_patma_098
match x: match x:
case NOT_YET_IMPLEMENTED_Pattern: case "NOT_YET_IMPLEMENTED_PatternMatchValue":
y = 0 y = 0
# case black_test_patma_142 # case black_test_patma_142
match x: match x:
case NOT_YET_IMPLEMENTED_Pattern: case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
y = 0 y = 0
# case black_test_patma_073 # case black_test_patma_073
match x: match x:
case NOT_YET_IMPLEMENTED_Pattern if 0: case "NOT_YET_IMPLEMENTED_PatternMatchValue" if 0:
y = 0 y = 0
case NOT_YET_IMPLEMENTED_Pattern if 1: case "NOT_YET_IMPLEMENTED_PatternMatchValue" if 1:
y = 1 y = 1
# case black_test_patma_006 # case black_test_patma_006
match 3: match 3:
case NOT_YET_IMPLEMENTED_Pattern: case NOT_YET_IMPLEMENTED_PatternMatchOf | (y):
x = True x = True
# case black_test_patma_049 # case black_test_patma_049
match x: match x:
case NOT_YET_IMPLEMENTED_Pattern: case NOT_YET_IMPLEMENTED_PatternMatchOf | (y):
y = 0 y = 0
# case black_check_sequence_then_mapping # case black_check_sequence_then_mapping
match x: match x:
case NOT_YET_IMPLEMENTED_Pattern: case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
return "seq" return "seq"
case NOT_YET_IMPLEMENTED_Pattern: case {"NOT_YET_IMPLEMENTED_PatternMatchMapping": _, 2: _}:
return "map" return "map"
# case black_test_patma_035 # case black_test_patma_035
match x: match x:
case NOT_YET_IMPLEMENTED_Pattern: case {"NOT_YET_IMPLEMENTED_PatternMatchMapping": _, 2: _}:
y = 0 y = 0
case NOT_YET_IMPLEMENTED_Pattern: case NOT_YET_IMPLEMENTED_PatternMatchOf | (y):
y = 1 y = 1
case NOT_YET_IMPLEMENTED_Pattern: case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
y = 2 y = 2
# case black_test_patma_107 # case black_test_patma_107
match x: match x:
case NOT_YET_IMPLEMENTED_Pattern: case "NOT_YET_IMPLEMENTED_PatternMatchValue":
y = 0 y = 0
# case black_test_patma_097 # case black_test_patma_097
match x: match x:
case NOT_YET_IMPLEMENTED_Pattern: case "NOT_YET_IMPLEMENTED_PatternMatchValue":
y = 0 y = 0
# case black_test_patma_007 # case black_test_patma_007
match 4: match 4:
case NOT_YET_IMPLEMENTED_Pattern: case NOT_YET_IMPLEMENTED_PatternMatchOf | (y):
x = True x = True
# case black_test_patma_154 # case black_test_patma_154
match x: match x:
case NOT_YET_IMPLEMENTED_Pattern if x: case "NOT_YET_IMPLEMENTED_PatternMatchValue" if x:
y = 0 y = 0
# case black_test_patma_134 # case black_test_patma_134
match x: match x:
case NOT_YET_IMPLEMENTED_Pattern: case {"NOT_YET_IMPLEMENTED_PatternMatchMapping": _, 2: _}:
y = 0 y = 0
case NOT_YET_IMPLEMENTED_Pattern: case {"NOT_YET_IMPLEMENTED_PatternMatchMapping": _, 2: _}:
y = 1 y = 1
case NOT_YET_IMPLEMENTED_Pattern: case {"NOT_YET_IMPLEMENTED_PatternMatchMapping": _, 2: _}:
y = 2 y = 2
# case black_test_patma_185 # case black_test_patma_185
match Seq(): match Seq():
case NOT_YET_IMPLEMENTED_Pattern: case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
y = 0 y = 0
# case black_test_patma_063 # case black_test_patma_063
match x: match x:
case NOT_YET_IMPLEMENTED_Pattern: case "NOT_YET_IMPLEMENTED_PatternMatchValue":
y = 0 y = 0
case NOT_YET_IMPLEMENTED_Pattern: case "NOT_YET_IMPLEMENTED_PatternMatchValue":
y = 1 y = 1
# case black_test_patma_248 # case black_test_patma_248
match x: match x:
case NOT_YET_IMPLEMENTED_Pattern: case {"NOT_YET_IMPLEMENTED_PatternMatchMapping": _, 2: _}:
y = bar y = bar
# case black_test_patma_019 # case black_test_patma_019
match (0, 1, 2): match (0, 1, 2):
case NOT_YET_IMPLEMENTED_Pattern: case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
y = 0 y = 0
# case black_test_patma_052 # case black_test_patma_052
match x: match x:
case NOT_YET_IMPLEMENTED_Pattern: case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
y = 0 y = 0
case NOT_YET_IMPLEMENTED_Pattern if (x := x[:0]): case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2] if (x := x[:0]):
y = 1 y = 1
case NOT_YET_IMPLEMENTED_Pattern: case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
y = 2 y = 2
# case black_test_patma_191 # case black_test_patma_191
match w: match w:
case NOT_YET_IMPLEMENTED_Pattern: case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
z = 0 z = 0
# case black_test_patma_110 # case black_test_patma_110
match x: match x:
case NOT_YET_IMPLEMENTED_Pattern: case "NOT_YET_IMPLEMENTED_PatternMatchValue":
y = 0 y = 0
# case black_test_patma_151 # case black_test_patma_151
match (x,): match (x,):
case NOT_YET_IMPLEMENTED_Pattern: case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
z = 0 z = 0
# case black_test_patma_114 # case black_test_patma_114
match x: match x:
case NOT_YET_IMPLEMENTED_Pattern: case "NOT_YET_IMPLEMENTED_PatternMatchValue":
y = 0 y = 0
# case black_test_patma_232 # case black_test_patma_232
match x: match x:
case NOT_YET_IMPLEMENTED_Pattern: case None:
y = 0 y = 0
# case black_test_patma_058 # case black_test_patma_058
match x: match x:
case NOT_YET_IMPLEMENTED_Pattern: case "NOT_YET_IMPLEMENTED_PatternMatchValue":
y = 0 y = 0
# case black_test_patma_233 # case black_test_patma_233
match x: match x:
case NOT_YET_IMPLEMENTED_Pattern: case None:
y = 0 y = 0
# case black_test_patma_078 # case black_test_patma_078
match x: match x:
case NOT_YET_IMPLEMENTED_Pattern: case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
y = 0 y = 0
case NOT_YET_IMPLEMENTED_Pattern: case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
y = 1 y = 1
case NOT_YET_IMPLEMENTED_Pattern: case "NOT_YET_IMPLEMENTED_PatternMatchValue":
y = 2 y = 2
# case black_test_patma_156 # case black_test_patma_156
match x: match x:
case NOT_YET_IMPLEMENTED_Pattern: case x as NOT_YET_IMPLEMENTED_PatternMatchAs:
y = 0 y = 0
# case black_test_patma_189 # case black_test_patma_189
match w: match w:
case NOT_YET_IMPLEMENTED_Pattern: case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
z = 0 z = 0
# case black_test_patma_042 # case black_test_patma_042
match x: match x:
case NOT_YET_IMPLEMENTED_Pattern if z == x % 2: case NOT_YET_IMPLEMENTED_PatternMatchOf | (y) if z == x % 2:
y = 0 y = 0
# case black_test_patma_034 # case black_test_patma_034
match x: match x:
case NOT_YET_IMPLEMENTED_Pattern: case {"NOT_YET_IMPLEMENTED_PatternMatchMapping": _, 2: _}:
y = 0 y = 0
case NOT_YET_IMPLEMENTED_Pattern: case NOT_YET_IMPLEMENTED_PatternMatchOf | (y):
y = 1 y = 1
case NOT_YET_IMPLEMENTED_Pattern: case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
y = 2 y = 2
``` ```

View file

@ -136,16 +136,16 @@ match bar1:
match something: match something:
- case [a as b]: - case [a as b]:
+ case NOT_YET_IMPLEMENTED_Pattern: + case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
print(b) print(b)
- case [a as b, c, d, e as f]: - case [a as b, c, d, e as f]:
+ case NOT_YET_IMPLEMENTED_Pattern: + case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
print(f) print(f)
- case Point(a as b): - case Point(a as b):
+ case NOT_YET_IMPLEMENTED_Pattern: + case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
print(b) print(b)
- case Point(int() as x, int() as y): - case Point(int() as x, int() as y):
+ case NOT_YET_IMPLEMENTED_Pattern: + case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
print(x, y) print(x, y)
@ -154,29 +154,29 @@ match bar1:
match re.match(case): match re.match(case):
- case type("match", match): - case type("match", match):
+ case NOT_YET_IMPLEMENTED_Pattern: + case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
pass pass
- case match: - case match:
+ case NOT_YET_IMPLEMENTED_Pattern: + case x as NOT_YET_IMPLEMENTED_PatternMatchAs:
pass pass
def func(match: case, case: match) -> case: def func(match: case, case: match) -> case:
match Something(): match Something():
- case func(match, case): - case func(match, case):
+ case NOT_YET_IMPLEMENTED_Pattern: + case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
... ...
- case another: - case another:
+ case NOT_YET_IMPLEMENTED_Pattern: + case x as NOT_YET_IMPLEMENTED_PatternMatchAs:
... ...
match maybe, multiple: match maybe, multiple:
- case perhaps, 5: - case perhaps, 5:
+ case NOT_YET_IMPLEMENTED_Pattern: + case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
pass pass
- case perhaps, 6,: - case perhaps, 6,:
+ case NOT_YET_IMPLEMENTED_Pattern: + case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
pass pass
@ -186,22 +186,22 @@ match bar1:
+ more := (than, one), + more := (than, one),
+ indeed, + indeed,
+): +):
+ case NOT_YET_IMPLEMENTED_Pattern: + case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
pass pass
- case [[5], (6)], [7],: - case [[5], (6)], [7],:
+ case NOT_YET_IMPLEMENTED_Pattern: + case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
pass pass
- case _: - case _:
+ case NOT_YET_IMPLEMENTED_Pattern: + case x as NOT_YET_IMPLEMENTED_PatternMatchAs:
pass pass
match a, *b, c: match a, *b, c:
- case [*_]: - case [*_]:
+ case NOT_YET_IMPLEMENTED_Pattern: + case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
assert "seq" == _ assert "seq" == _
- case {}: - case {}:
+ case NOT_YET_IMPLEMENTED_Pattern: + case {"NOT_YET_IMPLEMENTED_PatternMatchMapping": _, 2: _}:
assert "map" == b assert "map" == b
@ -215,27 +215,27 @@ match bar1:
- loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong - loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong
- ), - ),
- ): - ):
+ case NOT_YET_IMPLEMENTED_Pattern: + case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
pass pass
- case [a as match]: - case [a as match]:
+ case NOT_YET_IMPLEMENTED_Pattern: + case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
pass pass
- case case: - case case:
+ case NOT_YET_IMPLEMENTED_Pattern: + case x as NOT_YET_IMPLEMENTED_PatternMatchAs:
pass pass
match match: match match:
- case case: - case case:
+ case NOT_YET_IMPLEMENTED_Pattern: + case x as NOT_YET_IMPLEMENTED_PatternMatchAs:
pass pass
match a, *b(), c: match a, *b(), c:
- case d, *f, g: - case d, *f, g:
+ case NOT_YET_IMPLEMENTED_Pattern: + case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
pass pass
@ -244,33 +244,33 @@ match bar1:
- "key": key as key_1, - "key": key as key_1,
- "password": PASS.ONE | PASS.TWO | PASS.THREE as password, - "password": PASS.ONE | PASS.TWO | PASS.THREE as password,
- }: - }:
+ case NOT_YET_IMPLEMENTED_Pattern: + case {"NOT_YET_IMPLEMENTED_PatternMatchMapping": _, 2: _}:
pass pass
- case {"maybe": something(complicated as this) as that}: - case {"maybe": something(complicated as this) as that}:
+ case NOT_YET_IMPLEMENTED_Pattern: + case {"NOT_YET_IMPLEMENTED_PatternMatchMapping": _, 2: _}:
pass pass
match something: match something:
- case 1 as a: - case 1 as a:
+ case NOT_YET_IMPLEMENTED_Pattern: + case x as NOT_YET_IMPLEMENTED_PatternMatchAs:
pass pass
- case 2 as b, 3 as c: - case 2 as b, 3 as c:
+ case NOT_YET_IMPLEMENTED_Pattern: + case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
pass pass
- case 4 as d, (5 as e), (6 | 7 as g), *h: - case 4 as d, (5 as e), (6 | 7 as g), *h:
+ case NOT_YET_IMPLEMENTED_Pattern: + case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
pass pass
match bar1: match bar1:
- case Foo(aa=Callable() as aa, bb=int()): - case Foo(aa=Callable() as aa, bb=int()):
+ case NOT_YET_IMPLEMENTED_Pattern: + case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
print(bar1.aa, bar1.bb) print(bar1.aa, bar1.bb)
- case _: - case _:
+ case NOT_YET_IMPLEMENTED_Pattern: + case x as NOT_YET_IMPLEMENTED_PatternMatchAs:
print("no match", "\n") print("no match", "\n")
@ -278,7 +278,7 @@ match bar1:
- case Foo( - case Foo(
- normal=x, perhaps=[list, {"x": d, "y": 1.0}] as y, otherwise=something, q=t as u - normal=x, perhaps=[list, {"x": d, "y": 1.0}] as y, otherwise=something, q=t as u
- ): - ):
+ case NOT_YET_IMPLEMENTED_Pattern: + case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
pass pass
``` ```
@ -288,13 +288,13 @@ match bar1:
import match import match
match something: match something:
case NOT_YET_IMPLEMENTED_Pattern: case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
print(b) print(b)
case NOT_YET_IMPLEMENTED_Pattern: case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
print(f) print(f)
case NOT_YET_IMPLEMENTED_Pattern: case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
print(b) print(b)
case NOT_YET_IMPLEMENTED_Pattern: case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
print(x, y) print(x, y)
@ -302,24 +302,24 @@ match = 1
case: int = re.match(something) case: int = re.match(something)
match re.match(case): match re.match(case):
case NOT_YET_IMPLEMENTED_Pattern: case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
pass pass
case NOT_YET_IMPLEMENTED_Pattern: case x as NOT_YET_IMPLEMENTED_PatternMatchAs:
pass pass
def func(match: case, case: match) -> case: def func(match: case, case: match) -> case:
match Something(): match Something():
case NOT_YET_IMPLEMENTED_Pattern: case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
... ...
case NOT_YET_IMPLEMENTED_Pattern: case x as NOT_YET_IMPLEMENTED_PatternMatchAs:
... ...
match maybe, multiple: match maybe, multiple:
case NOT_YET_IMPLEMENTED_Pattern: case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
pass pass
case NOT_YET_IMPLEMENTED_Pattern: case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
pass pass
@ -327,18 +327,18 @@ match (
more := (than, one), more := (than, one),
indeed, indeed,
): ):
case NOT_YET_IMPLEMENTED_Pattern: case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
pass pass
case NOT_YET_IMPLEMENTED_Pattern: case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
pass pass
case NOT_YET_IMPLEMENTED_Pattern: case x as NOT_YET_IMPLEMENTED_PatternMatchAs:
pass pass
match a, *b, c: match a, *b, c:
case NOT_YET_IMPLEMENTED_Pattern: case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
assert "seq" == _ assert "seq" == _
case NOT_YET_IMPLEMENTED_Pattern: case {"NOT_YET_IMPLEMENTED_PatternMatchMapping": _, 2: _}:
assert "map" == b assert "map" == b
@ -349,53 +349,53 @@ match match(
), ),
case, case,
): ):
case NOT_YET_IMPLEMENTED_Pattern: case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
pass pass
case NOT_YET_IMPLEMENTED_Pattern: case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
pass pass
case NOT_YET_IMPLEMENTED_Pattern: case x as NOT_YET_IMPLEMENTED_PatternMatchAs:
pass pass
match match: match match:
case NOT_YET_IMPLEMENTED_Pattern: case x as NOT_YET_IMPLEMENTED_PatternMatchAs:
pass pass
match a, *b(), c: match a, *b(), c:
case NOT_YET_IMPLEMENTED_Pattern: case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
pass pass
match something: match something:
case NOT_YET_IMPLEMENTED_Pattern: case {"NOT_YET_IMPLEMENTED_PatternMatchMapping": _, 2: _}:
pass pass
case NOT_YET_IMPLEMENTED_Pattern: case {"NOT_YET_IMPLEMENTED_PatternMatchMapping": _, 2: _}:
pass pass
match something: match something:
case NOT_YET_IMPLEMENTED_Pattern: case x as NOT_YET_IMPLEMENTED_PatternMatchAs:
pass pass
case NOT_YET_IMPLEMENTED_Pattern: case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
pass pass
case NOT_YET_IMPLEMENTED_Pattern: case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
pass pass
match bar1: match bar1:
case NOT_YET_IMPLEMENTED_Pattern: case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
print(bar1.aa, bar1.bb) print(bar1.aa, bar1.bb)
case NOT_YET_IMPLEMENTED_Pattern: case x as NOT_YET_IMPLEMENTED_PatternMatchAs:
print("no match", "\n") print("no match", "\n")
match bar1: match bar1:
case NOT_YET_IMPLEMENTED_Pattern: case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
pass pass
``` ```

View file

@ -124,10 +124,10 @@ with match() as match:
match match: match match:
- case case: - case case:
+ case NOT_YET_IMPLEMENTED_Pattern: + case x as NOT_YET_IMPLEMENTED_PatternMatchAs:
match match: match match:
- case case: - case case:
+ case NOT_YET_IMPLEMENTED_Pattern: + case x as NOT_YET_IMPLEMENTED_PatternMatchAs:
pass pass
if all(version.is_python2() for version in target_versions): if all(version.is_python2() for version in target_versions):
@ -136,7 +136,7 @@ with match() as match:
x = False x = False
match x: match x:
- case bool(z): - case bool(z):
+ case NOT_YET_IMPLEMENTED_Pattern: + case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
y = 0 y = 0
self.assertIs(x, False) self.assertIs(x, False)
self.assertEqual(y, 0) self.assertEqual(y, 0)
@ -145,7 +145,7 @@ with match() as match:
y = None y = None
match x: match x:
- case 1e1000: - case 1e1000:
+ case NOT_YET_IMPLEMENTED_Pattern: + case "NOT_YET_IMPLEMENTED_PatternMatchValue":
y = 0 y = 0
self.assertEqual(x, 0) self.assertEqual(x, 0)
self.assertIs(y, None) self.assertIs(y, None)
@ -153,7 +153,7 @@ with match() as match:
x = range(3) x = range(3)
match x: match x:
- case [y, case as x, z]: - case [y, case as x, z]:
+ case NOT_YET_IMPLEMENTED_Pattern: + case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
w = 0 w = 0
# At least one of the above branches must have been taken, because every Python # At least one of the above branches must have been taken, because every Python
@ -188,9 +188,9 @@ def get_grammars(target_versions: Set[TargetVersion]) -> List[Grammar]:
] ]
match match: match match:
case NOT_YET_IMPLEMENTED_Pattern: case x as NOT_YET_IMPLEMENTED_PatternMatchAs:
match match: match match:
case NOT_YET_IMPLEMENTED_Pattern: case x as NOT_YET_IMPLEMENTED_PatternMatchAs:
pass pass
if all(version.is_python2() for version in target_versions): if all(version.is_python2() for version in target_versions):
@ -210,7 +210,7 @@ def get_grammars(target_versions: Set[TargetVersion]) -> List[Grammar]:
def test_patma_139(self): def test_patma_139(self):
x = False x = False
match x: match x:
case NOT_YET_IMPLEMENTED_Pattern: case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
y = 0 y = 0
self.assertIs(x, False) self.assertIs(x, False)
self.assertEqual(y, 0) self.assertEqual(y, 0)
@ -237,14 +237,14 @@ def get_grammars(target_versions: Set[TargetVersion]) -> List[Grammar]:
x = 0 x = 0
y = None y = None
match x: match x:
case NOT_YET_IMPLEMENTED_Pattern: case "NOT_YET_IMPLEMENTED_PatternMatchValue":
y = 0 y = 0
self.assertEqual(x, 0) self.assertEqual(x, 0)
self.assertIs(y, None) self.assertIs(y, None)
x = range(3) x = range(3)
match x: match x:
case NOT_YET_IMPLEMENTED_Pattern: case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
w = 0 w = 0
# At least one of the above branches must have been taken, because every Python # At least one of the above branches must have been taken, because every Python

View file

@ -109,123 +109,123 @@ def where_is(point):
match command.split(): match command.split():
- case [action, obj]: - case [action, obj]:
+ case NOT_YET_IMPLEMENTED_Pattern: + case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
... # interpret action, obj ... # interpret action, obj
match command.split(): match command.split():
- case [action]: - case [action]:
+ case NOT_YET_IMPLEMENTED_Pattern: + case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
... # interpret single-verb action ... # interpret single-verb action
- case [action, obj]: - case [action, obj]:
+ case NOT_YET_IMPLEMENTED_Pattern: + case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
... # interpret action, obj ... # interpret action, obj
match command.split(): match command.split():
- case ["quit"]: - case ["quit"]:
+ case NOT_YET_IMPLEMENTED_Pattern: + case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
print("Goodbye!") print("Goodbye!")
quit_game() quit_game()
- case ["look"]: - case ["look"]:
+ case NOT_YET_IMPLEMENTED_Pattern: + case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
current_room.describe() current_room.describe()
- case ["get", obj]: - case ["get", obj]:
+ case NOT_YET_IMPLEMENTED_Pattern: + case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
character.get(obj, current_room) character.get(obj, current_room)
- case ["go", direction]: - case ["go", direction]:
+ case NOT_YET_IMPLEMENTED_Pattern: + case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
current_room = current_room.neighbor(direction) current_room = current_room.neighbor(direction)
# The rest of your commands go here # The rest of your commands go here
match command.split(): match command.split():
- case ["drop", *objects]: - case ["drop", *objects]:
+ case NOT_YET_IMPLEMENTED_Pattern: + case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
for obj in objects: for obj in objects:
character.drop(obj, current_room) character.drop(obj, current_room)
# The rest of your commands go here # The rest of your commands go here
match command.split(): match command.split():
- case ["quit"]: - case ["quit"]:
+ case NOT_YET_IMPLEMENTED_Pattern: + case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
pass pass
- case ["go", direction]: - case ["go", direction]:
+ case NOT_YET_IMPLEMENTED_Pattern: + case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
print("Going:", direction) print("Going:", direction)
- case ["drop", *objects]: - case ["drop", *objects]:
+ case NOT_YET_IMPLEMENTED_Pattern: + case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
print("Dropping: ", *objects) print("Dropping: ", *objects)
- case _: - case _:
+ case NOT_YET_IMPLEMENTED_Pattern: + case x as NOT_YET_IMPLEMENTED_PatternMatchAs:
print(f"Sorry, I couldn't understand {command!r}") print(f"Sorry, I couldn't understand {command!r}")
match command.split(): match command.split():
- case ["north"] | ["go", "north"]: - case ["north"] | ["go", "north"]:
+ case NOT_YET_IMPLEMENTED_Pattern: + case NOT_YET_IMPLEMENTED_PatternMatchOf | (y):
current_room = current_room.neighbor("north") current_room = current_room.neighbor("north")
- case ["get", obj] | ["pick", "up", obj] | ["pick", obj, "up"]: - case ["get", obj] | ["pick", "up", obj] | ["pick", obj, "up"]:
+ case NOT_YET_IMPLEMENTED_Pattern: + case NOT_YET_IMPLEMENTED_PatternMatchOf | (y):
... # Code for picking up the given object ... # Code for picking up the given object
match command.split(): match command.split():
- case ["go", ("north" | "south" | "east" | "west")]: - case ["go", ("north" | "south" | "east" | "west")]:
+ case NOT_YET_IMPLEMENTED_Pattern: + case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
current_room = current_room.neighbor(...) current_room = current_room.neighbor(...)
# how do I know which direction to go? # how do I know which direction to go?
match command.split(): match command.split():
- case ["go", ("north" | "south" | "east" | "west") as direction]: - case ["go", ("north" | "south" | "east" | "west") as direction]:
+ case NOT_YET_IMPLEMENTED_Pattern: + case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
current_room = current_room.neighbor(direction) current_room = current_room.neighbor(direction)
match command.split(): match command.split():
- case ["go", direction] if direction in current_room.exits: - case ["go", direction] if direction in current_room.exits:
+ case NOT_YET_IMPLEMENTED_Pattern if direction in current_room.exits: + case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2] if direction in current_room.exits:
current_room = current_room.neighbor(direction) current_room = current_room.neighbor(direction)
- case ["go", _]: - case ["go", _]:
+ case NOT_YET_IMPLEMENTED_Pattern: + case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
print("Sorry, you can't go that way") print("Sorry, you can't go that way")
match event.get(): match event.get():
- case Click(position=(x, y)): - case Click(position=(x, y)):
+ case NOT_YET_IMPLEMENTED_Pattern: + case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
handle_click_at(x, y) handle_click_at(x, y)
- case KeyPress(key_name="Q") | Quit(): - case KeyPress(key_name="Q") | Quit():
+ case NOT_YET_IMPLEMENTED_Pattern: + case NOT_YET_IMPLEMENTED_PatternMatchOf | (y):
game.quit() game.quit()
- case KeyPress(key_name="up arrow"): - case KeyPress(key_name="up arrow"):
+ case NOT_YET_IMPLEMENTED_Pattern: + case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
game.go_north() game.go_north()
- case KeyPress(): - case KeyPress():
+ case NOT_YET_IMPLEMENTED_Pattern: + case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
pass # Ignore other keystrokes pass # Ignore other keystrokes
- case other_event: - case other_event:
+ case NOT_YET_IMPLEMENTED_Pattern: + case x as NOT_YET_IMPLEMENTED_PatternMatchAs:
raise ValueError(f"Unrecognized event: {other_event}") raise ValueError(f"Unrecognized event: {other_event}")
match event.get(): match event.get():
- case Click((x, y), button=Button.LEFT): # This is a left click - case Click((x, y), button=Button.LEFT): # This is a left click
+ case NOT_YET_IMPLEMENTED_Pattern: # This is a left click + case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0): # This is a left click
handle_click_at(x, y) handle_click_at(x, y)
- case Click(): - case Click():
+ case NOT_YET_IMPLEMENTED_Pattern: + case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
pass # ignore other clicks pass # ignore other clicks
def where_is(point): def where_is(point):
match point: match point:
- case Point(x=0, y=0): - case Point(x=0, y=0):
+ case NOT_YET_IMPLEMENTED_Pattern: + case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
print("Origin") print("Origin")
- case Point(x=0, y=y): - case Point(x=0, y=y):
+ case NOT_YET_IMPLEMENTED_Pattern: + case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
print(f"Y={y}") print(f"Y={y}")
- case Point(x=x, y=0): - case Point(x=x, y=0):
+ case NOT_YET_IMPLEMENTED_Pattern: + case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
print(f"X={x}") print(f"X={x}")
- case Point(): - case Point():
+ case NOT_YET_IMPLEMENTED_Pattern: + case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
print("Somewhere else") print("Somewhere else")
- case _: - case _:
+ case NOT_YET_IMPLEMENTED_Pattern: + case x as NOT_YET_IMPLEMENTED_PatternMatchAs:
print("Not a point") print("Not a point")
``` ```
@ -235,94 +235,94 @@ def where_is(point):
# Cases sampled from PEP 636 examples # Cases sampled from PEP 636 examples
match command.split(): match command.split():
case NOT_YET_IMPLEMENTED_Pattern: case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
... # interpret action, obj ... # interpret action, obj
match command.split(): match command.split():
case NOT_YET_IMPLEMENTED_Pattern: case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
... # interpret single-verb action ... # interpret single-verb action
case NOT_YET_IMPLEMENTED_Pattern: case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
... # interpret action, obj ... # interpret action, obj
match command.split(): match command.split():
case NOT_YET_IMPLEMENTED_Pattern: case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
print("Goodbye!") print("Goodbye!")
quit_game() quit_game()
case NOT_YET_IMPLEMENTED_Pattern: case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
current_room.describe() current_room.describe()
case NOT_YET_IMPLEMENTED_Pattern: case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
character.get(obj, current_room) character.get(obj, current_room)
case NOT_YET_IMPLEMENTED_Pattern: case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
current_room = current_room.neighbor(direction) current_room = current_room.neighbor(direction)
# The rest of your commands go here # The rest of your commands go here
match command.split(): match command.split():
case NOT_YET_IMPLEMENTED_Pattern: case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
for obj in objects: for obj in objects:
character.drop(obj, current_room) character.drop(obj, current_room)
# The rest of your commands go here # The rest of your commands go here
match command.split(): match command.split():
case NOT_YET_IMPLEMENTED_Pattern: case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
pass pass
case NOT_YET_IMPLEMENTED_Pattern: case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
print("Going:", direction) print("Going:", direction)
case NOT_YET_IMPLEMENTED_Pattern: case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
print("Dropping: ", *objects) print("Dropping: ", *objects)
case NOT_YET_IMPLEMENTED_Pattern: case x as NOT_YET_IMPLEMENTED_PatternMatchAs:
print(f"Sorry, I couldn't understand {command!r}") print(f"Sorry, I couldn't understand {command!r}")
match command.split(): match command.split():
case NOT_YET_IMPLEMENTED_Pattern: case NOT_YET_IMPLEMENTED_PatternMatchOf | (y):
current_room = current_room.neighbor("north") current_room = current_room.neighbor("north")
case NOT_YET_IMPLEMENTED_Pattern: case NOT_YET_IMPLEMENTED_PatternMatchOf | (y):
... # Code for picking up the given object ... # Code for picking up the given object
match command.split(): match command.split():
case NOT_YET_IMPLEMENTED_Pattern: case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
current_room = current_room.neighbor(...) current_room = current_room.neighbor(...)
# how do I know which direction to go? # how do I know which direction to go?
match command.split(): match command.split():
case NOT_YET_IMPLEMENTED_Pattern: case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
current_room = current_room.neighbor(direction) current_room = current_room.neighbor(direction)
match command.split(): match command.split():
case NOT_YET_IMPLEMENTED_Pattern if direction in current_room.exits: case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2] if direction in current_room.exits:
current_room = current_room.neighbor(direction) current_room = current_room.neighbor(direction)
case NOT_YET_IMPLEMENTED_Pattern: case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
print("Sorry, you can't go that way") print("Sorry, you can't go that way")
match event.get(): match event.get():
case NOT_YET_IMPLEMENTED_Pattern: case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
handle_click_at(x, y) handle_click_at(x, y)
case NOT_YET_IMPLEMENTED_Pattern: case NOT_YET_IMPLEMENTED_PatternMatchOf | (y):
game.quit() game.quit()
case NOT_YET_IMPLEMENTED_Pattern: case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
game.go_north() game.go_north()
case NOT_YET_IMPLEMENTED_Pattern: case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
pass # Ignore other keystrokes pass # Ignore other keystrokes
case NOT_YET_IMPLEMENTED_Pattern: case x as NOT_YET_IMPLEMENTED_PatternMatchAs:
raise ValueError(f"Unrecognized event: {other_event}") raise ValueError(f"Unrecognized event: {other_event}")
match event.get(): match event.get():
case NOT_YET_IMPLEMENTED_Pattern: # This is a left click case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0): # This is a left click
handle_click_at(x, y) handle_click_at(x, y)
case NOT_YET_IMPLEMENTED_Pattern: case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
pass # ignore other clicks pass # ignore other clicks
def where_is(point): def where_is(point):
match point: match point:
case NOT_YET_IMPLEMENTED_Pattern: case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
print("Origin") print("Origin")
case NOT_YET_IMPLEMENTED_Pattern: case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
print(f"Y={y}") print(f"Y={y}")
case NOT_YET_IMPLEMENTED_Pattern: case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
print(f"X={x}") print(f"X={x}")
case NOT_YET_IMPLEMENTED_Pattern: case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
print("Somewhere else") print("Somewhere else")
case NOT_YET_IMPLEMENTED_Pattern: case x as NOT_YET_IMPLEMENTED_PatternMatchAs:
print("Not a point") print("Not a point")
``` ```

View file

@ -68,21 +68,21 @@ match match(
@@ -1,35 +1,34 @@ @@ -1,35 +1,34 @@
match something: match something:
- case b(): - case b():
+ case NOT_YET_IMPLEMENTED_Pattern: + case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
print(1 + 1) print(1 + 1)
- case c( - case c(
- very_complex=True, perhaps_even_loooooooooooooooooooooooooooooooooooooong=-1 - very_complex=True, perhaps_even_loooooooooooooooooooooooooooooooooooooong=-1
- ): - ):
+ case NOT_YET_IMPLEMENTED_Pattern: + case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
print(1) print(1)
- case c( - case c(
- very_complex=True, - very_complex=True,
- perhaps_even_loooooooooooooooooooooooooooooooooooooong=-1, - perhaps_even_loooooooooooooooooooooooooooooooooooooong=-1,
- ): - ):
+ case NOT_YET_IMPLEMENTED_Pattern: + case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
print(2) print(2)
- case a: - case a:
+ case NOT_YET_IMPLEMENTED_Pattern: + case x as NOT_YET_IMPLEMENTED_PatternMatchAs:
pass pass
-match(arg) # comment -match(arg) # comment
@ -113,7 +113,7 @@ match match(
- case case( - case case(
- arg, # comment - arg, # comment
- ): - ):
+ case NOT_YET_IMPLEMENTED_Pattern: + case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
pass pass
``` ```
@ -121,13 +121,13 @@ match match(
```py ```py
match something: match something:
case NOT_YET_IMPLEMENTED_Pattern: case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
print(1 + 1) print(1 + 1)
case NOT_YET_IMPLEMENTED_Pattern: case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
print(1) print(1)
case NOT_YET_IMPLEMENTED_Pattern: case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
print(2) print(2)
case NOT_YET_IMPLEMENTED_Pattern: case x as NOT_YET_IMPLEMENTED_PatternMatchAs:
pass pass
match( match(
@ -152,7 +152,7 @@ re.match(
) )
re.match() re.match()
match match(): match match():
case NOT_YET_IMPLEMENTED_Pattern: case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
pass pass
``` ```

View file

@ -35,19 +35,19 @@ def http_status(status):
def http_status(status): def http_status(status):
match status: match status:
- case 400: - case 400:
+ case NOT_YET_IMPLEMENTED_Pattern: + case "NOT_YET_IMPLEMENTED_PatternMatchValue":
return "Bad request" return "Bad request"
- case 401: - case 401:
+ case NOT_YET_IMPLEMENTED_Pattern: + case "NOT_YET_IMPLEMENTED_PatternMatchValue":
return "Unauthorized" return "Unauthorized"
- case 403: - case 403:
+ case NOT_YET_IMPLEMENTED_Pattern: + case "NOT_YET_IMPLEMENTED_PatternMatchValue":
return "Forbidden" return "Forbidden"
- case 404: - case 404:
+ case NOT_YET_IMPLEMENTED_Pattern: + case "NOT_YET_IMPLEMENTED_PatternMatchValue":
return "Not found" return "Not found"
``` ```
@ -56,16 +56,16 @@ def http_status(status):
```py ```py
def http_status(status): def http_status(status):
match status: match status:
case NOT_YET_IMPLEMENTED_Pattern: case "NOT_YET_IMPLEMENTED_PatternMatchValue":
return "Bad request" return "Bad request"
case NOT_YET_IMPLEMENTED_Pattern: case "NOT_YET_IMPLEMENTED_PatternMatchValue":
return "Unauthorized" return "Unauthorized"
case NOT_YET_IMPLEMENTED_Pattern: case "NOT_YET_IMPLEMENTED_PatternMatchValue":
return "Forbidden" return "Forbidden"
case NOT_YET_IMPLEMENTED_Pattern: case "NOT_YET_IMPLEMENTED_PatternMatchValue":
return "Not found" return "Not found"
``` ```

View file

@ -139,10 +139,10 @@ with ( # d 1
pass pass
match ( # d 2 match ( # d 2
): ):
case NOT_YET_IMPLEMENTED_Pattern: case x as NOT_YET_IMPLEMENTED_PatternMatchAs:
pass pass
match d3: match d3:
case NOT_YET_IMPLEMENTED_Pattern: case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
pass pass
while ( # d 4 while ( # d 4
): ):

View file

@ -219,10 +219,13 @@ with ( # d 1
match ( # d 2 match ( # d 2
x x
): ):
case NOT_YET_IMPLEMENTED_Pattern: case x as NOT_YET_IMPLEMENTED_PatternMatchAs:
pass pass
match d3: match d3:
case NOT_YET_IMPLEMENTED_Pattern: case (
# d 3
x as NOT_YET_IMPLEMENTED_PatternMatchAs
):
pass pass
while ( # d 4 while ( # d 4
x x

View file

@ -114,13 +114,46 @@ match long_lines:
bbbbbbbbaaaaaahhhh == 2 bbbbbbbbaaaaaahhhh == 2
): # another comment ): # another comment
pass pass
match pattern_comments:
case (
only_trailing # trailing 1
# trailing 2
# trailing 3
):
pass
match pattern_comments:
case ( # leading
only_leading
):
pass
match pattern_comments:
case (
# leading
leading_and_trailing # trailing 1
# trailing 2
# trailing 3
):
pass
match pattern_comments:
case (
no_comments
):
pass
``` ```
## Output ## Output
```py ```py
# leading match comment # leading match comment
match foo: # dangling match comment match foo: # dangling match comment
case NOT_YET_IMPLEMENTED_Pattern: case "NOT_YET_IMPLEMENTED_PatternMatchValue":
pass pass
@ -130,7 +163,7 @@ match ( # leading expr comment
foo # trailing expr comment foo # trailing expr comment
# another trailing expr comment # another trailing expr comment
): # dangling match comment ): # dangling match comment
case NOT_YET_IMPLEMENTED_Pattern: case "NOT_YET_IMPLEMENTED_PatternMatchValue":
pass pass
@ -138,7 +171,7 @@ match ( # leading expr comment
match ( # hello match ( # hello
foo, # trailing expr comment # another foo, # trailing expr comment # another
): # dangling match comment ): # dangling match comment
case NOT_YET_IMPLEMENTED_Pattern: case "NOT_YET_IMPLEMENTED_PatternMatchValue":
pass pass
@ -147,13 +180,13 @@ match [ # comment
second, second,
third, third,
]: # another comment ]: # another comment
case NOT_YET_IMPLEMENTED_Pattern: case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
pass pass
match ( # comment match ( # comment
"a b c" "a b c"
).split(): # another comment ).split(): # another comment
case NOT_YET_IMPLEMENTED_Pattern: case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
pass pass
@ -161,65 +194,97 @@ match ( # comment
# let's go # let's go
yield foo yield foo
): # another comment ): # another comment
case NOT_YET_IMPLEMENTED_Pattern: case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
pass pass
match aaaaaaaaahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh: # comment match aaaaaaaaahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh: # comment
case NOT_YET_IMPLEMENTED_Pattern: case "NOT_YET_IMPLEMENTED_PatternMatchValue":
pass pass
def foo(): def foo():
match inside_func: # comment match inside_func: # comment
case NOT_YET_IMPLEMENTED_Pattern: case "NOT_YET_IMPLEMENTED_PatternMatchValue":
pass pass
match newlines: match newlines:
# case 1 leading comment # case 1 leading comment
case NOT_YET_IMPLEMENTED_Pattern: # case dangling comment case "NOT_YET_IMPLEMENTED_PatternMatchValue": # case dangling comment
# pass leading comment # pass leading comment
pass pass
# pass trailing comment # pass trailing comment
# case 2 leading comment # case 2 leading comment
case NOT_YET_IMPLEMENTED_Pattern if foo == 2: # second case "NOT_YET_IMPLEMENTED_PatternMatchValue" if foo == 2: # second
pass pass
case NOT_YET_IMPLEMENTED_Pattern if (foo := 1): # third case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2] if (foo := 1): # third
pass pass
case NOT_YET_IMPLEMENTED_Pattern: case "NOT_YET_IMPLEMENTED_PatternMatchValue":
pass pass
case NOT_YET_IMPLEMENTED_Pattern: case "NOT_YET_IMPLEMENTED_PatternMatchValue":
pass pass
case NOT_YET_IMPLEMENTED_Pattern: case x as NOT_YET_IMPLEMENTED_PatternMatchAs:
pass pass
match long_lines: match long_lines:
case NOT_YET_IMPLEMENTED_Pattern if aaaaaaaaahhhhhhhh == 1 and bbbbbbaaaaaaaaaaa == 2: # comment case "NOT_YET_IMPLEMENTED_PatternMatchValue" if aaaaaaaaahhhhhhhh == 1 and bbbbbbaaaaaaaaaaa == 2: # comment
pass pass
case NOT_YET_IMPLEMENTED_Pattern if ( case "NOT_YET_IMPLEMENTED_PatternMatchValue" if (
aaaaaaaaahhhhhhhh == 1 and bbbbbbaaaaaaaaaaa == 2 aaaaaaaaahhhhhhhh == 1 and bbbbbbaaaaaaaaaaa == 2
): # comment ): # comment
pass pass
case NOT_YET_IMPLEMENTED_Pattern if foo := 1: case "NOT_YET_IMPLEMENTED_PatternMatchValue" if foo := 1:
pass pass
case NOT_YET_IMPLEMENTED_Pattern if (foo := 1): case "NOT_YET_IMPLEMENTED_PatternMatchValue" if (foo := 1):
pass pass
case NOT_YET_IMPLEMENTED_Pattern if ( case "NOT_YET_IMPLEMENTED_PatternMatchValue" if (
aaaaaaahhhhhhhhhhh == 1 and bbbbbbbbaaaaaahhhh == 2 aaaaaaahhhhhhhhhhh == 1 and bbbbbbbbaaaaaahhhh == 2
): # another comment ): # another comment
pass pass
match pattern_comments:
case (
x as NOT_YET_IMPLEMENTED_PatternMatchAs # trailing 1
# trailing 2
# trailing 3
):
pass
match pattern_comments:
case (
# leading
x as NOT_YET_IMPLEMENTED_PatternMatchAs
):
pass
match pattern_comments:
case (
# leading
x as NOT_YET_IMPLEMENTED_PatternMatchAs # trailing 1
# trailing 2
# trailing 3
):
pass
match pattern_comments:
case (x as NOT_YET_IMPLEMENTED_PatternMatchAs):
pass
``` ```