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
): # another comment
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`.
#[allow(unused)]
pub(crate) fn leading_trailing_comments<T>(
&self,
node: T,

View file

@ -152,40 +152,6 @@ pub fn format_node<'a>(
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> {
text: &'static str,
node: AnyNodeRef<'a>,

View file

@ -1,10 +1,12 @@
use ruff_formatter::{write, Buffer, FormatResult};
use ruff_python_ast::MatchCase;
use ruff_formatter::{format_args, write, Buffer, FormatResult};
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::not_yet_implemented_custom_text;
use crate::comments::{leading_comments, trailing_comments, SourceComment};
use crate::expression::parentheses::parenthesized;
use crate::prelude::*;
use crate::{FormatNodeRule, PyFormatter};
use crate::{FormatError, FormatNodeRule, PyFormatter};
#[derive(Default)]
pub struct FormatMatchCase;
@ -21,25 +23,21 @@ impl FormatNodeRule<MatchCase> for FormatMatchCase {
let comments = f.context().comments().clone();
let dangling_item_comments = comments.dangling_comments(item);
write!(
f,
[
text("case"),
space(),
format_with(|f: &mut PyFormatter| {
let comments = f.context().comments();
for comment in comments.leading_trailing_comments(pattern) {
// This is a lie, but let's go with it.
comment.mark_formatted();
write!(f, [text("case"), space()])?;
let leading_pattern_comments = comments.leading_comments(pattern);
if !leading_pattern_comments.is_empty() {
parenthesized(
"(",
&format_args![leading_comments(leading_pattern_comments), pattern.format()],
")",
)
.fmt(f)?;
} else if is_match_case_pattern_parenthesized(item, pattern, f.context())? {
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 {
write!(f, [space(), text("if"), space(), guard.format()])?;
}
@ -63,3 +61,33 @@ impl FormatNodeRule<MatchCase> for FormatMatchCase {
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_python_ast::PatternMatchAs;
use crate::{not_yet_implemented_custom_text, FormatNodeRule, PyFormatter};
#[derive(Default)]
pub struct FormatPatternMatchAs;
impl FormatNodeRule<PatternMatchAs> for FormatPatternMatchAs {
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_python_ast::PatternMatchClass;
use crate::{not_yet_implemented_custom_text, 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(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_python_ast::PatternMatchMapping;
use crate::{not_yet_implemented_custom_text, FormatNodeRule, PyFormatter};
#[derive(Default)]
pub struct FormatPatternMatchMapping;
impl FormatNodeRule<PatternMatchMapping> for FormatPatternMatchMapping {
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_python_ast::PatternMatchOr;
use crate::{not_yet_implemented_custom_text, FormatNodeRule, PyFormatter};
#[derive(Default)]
pub struct FormatPatternMatchOr;
impl FormatNodeRule<PatternMatchOr> for FormatPatternMatchOr {
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_python_ast::PatternMatchSequence;
use crate::{not_yet_implemented_custom_text, FormatNodeRule, PyFormatter};
#[derive(Default)]
pub struct FormatPatternMatchSequence;
impl FormatNodeRule<PatternMatchSequence> for FormatPatternMatchSequence {
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_python_ast::PatternMatchSingleton;
use crate::{not_yet_implemented_custom_text, FormatNodeRule, PyFormatter};
#[derive(Default)]
pub struct FormatPatternMatchSingleton;
impl FormatNodeRule<PatternMatchSingleton> for FormatPatternMatchSingleton {
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_python_ast::PatternMatchStar;
use crate::{not_yet_implemented_custom_text, FormatNodeRule, PyFormatter};
#[derive(Default)]
pub struct FormatPatternMatchStar;
impl FormatNodeRule<PatternMatchStar> for FormatPatternMatchStar {
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_formatter::{write, Buffer, FormatResult};
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
use crate::{not_yet_implemented_custom_text, FormatNodeRule, PyFormatter};
#[derive(Default)]
pub struct FormatPatternMatchValue;
impl FormatNodeRule<PatternMatchValue> for FormatPatternMatchValue {
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!(
f,
[block_indent(&format_args!(
&leading_alternate_branch_comments(
leading_alternate_branch_comments(
comments.leading_comments(case),
last_case.body.last(),
),
&case.format()
case.format()
))]
)?;
last_case = case;

View file

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

View file

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

View file

@ -124,10 +124,10 @@ with match() as match:
match match:
- case case:
+ case NOT_YET_IMPLEMENTED_Pattern:
+ case x as NOT_YET_IMPLEMENTED_PatternMatchAs:
match match:
- case case:
+ case NOT_YET_IMPLEMENTED_Pattern:
+ case x as NOT_YET_IMPLEMENTED_PatternMatchAs:
pass
if all(version.is_python2() for version in target_versions):
@ -136,7 +136,7 @@ with match() as match:
x = False
match x:
- case bool(z):
+ case NOT_YET_IMPLEMENTED_Pattern:
+ case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
y = 0
self.assertIs(x, False)
self.assertEqual(y, 0)
@ -145,7 +145,7 @@ with match() as match:
y = None
match x:
- case 1e1000:
+ case NOT_YET_IMPLEMENTED_Pattern:
+ case "NOT_YET_IMPLEMENTED_PatternMatchValue":
y = 0
self.assertEqual(x, 0)
self.assertIs(y, None)
@ -153,7 +153,7 @@ with match() as match:
x = range(3)
match x:
- case [y, case as x, z]:
+ case NOT_YET_IMPLEMENTED_Pattern:
+ case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
w = 0
# 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:
case NOT_YET_IMPLEMENTED_Pattern:
case x as NOT_YET_IMPLEMENTED_PatternMatchAs:
match match:
case NOT_YET_IMPLEMENTED_Pattern:
case x as NOT_YET_IMPLEMENTED_PatternMatchAs:
pass
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):
x = False
match x:
case NOT_YET_IMPLEMENTED_Pattern:
case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
y = 0
self.assertIs(x, False)
self.assertEqual(y, 0)
@ -237,14 +237,14 @@ def get_grammars(target_versions: Set[TargetVersion]) -> List[Grammar]:
x = 0
y = None
match x:
case NOT_YET_IMPLEMENTED_Pattern:
case "NOT_YET_IMPLEMENTED_PatternMatchValue":
y = 0
self.assertEqual(x, 0)
self.assertIs(y, None)
x = range(3)
match x:
case NOT_YET_IMPLEMENTED_Pattern:
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
w = 0
# 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():
- case [action, obj]:
+ case NOT_YET_IMPLEMENTED_Pattern:
+ case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
... # interpret action, obj
match command.split():
- case [action]:
+ case NOT_YET_IMPLEMENTED_Pattern:
+ case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
... # interpret single-verb action
- case [action, obj]:
+ case NOT_YET_IMPLEMENTED_Pattern:
+ case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
... # interpret action, obj
match command.split():
- case ["quit"]:
+ case NOT_YET_IMPLEMENTED_Pattern:
+ case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
print("Goodbye!")
quit_game()
- case ["look"]:
+ case NOT_YET_IMPLEMENTED_Pattern:
+ case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
current_room.describe()
- case ["get", obj]:
+ case NOT_YET_IMPLEMENTED_Pattern:
+ case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
character.get(obj, current_room)
- case ["go", direction]:
+ case NOT_YET_IMPLEMENTED_Pattern:
+ case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
current_room = current_room.neighbor(direction)
# The rest of your commands go here
match command.split():
- case ["drop", *objects]:
+ case NOT_YET_IMPLEMENTED_Pattern:
+ case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
for obj in objects:
character.drop(obj, current_room)
# The rest of your commands go here
match command.split():
- case ["quit"]:
+ case NOT_YET_IMPLEMENTED_Pattern:
+ case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
pass
- case ["go", direction]:
+ case NOT_YET_IMPLEMENTED_Pattern:
+ case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
print("Going:", direction)
- case ["drop", *objects]:
+ case NOT_YET_IMPLEMENTED_Pattern:
+ case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
print("Dropping: ", *objects)
- case _:
+ case NOT_YET_IMPLEMENTED_Pattern:
+ case x as NOT_YET_IMPLEMENTED_PatternMatchAs:
print(f"Sorry, I couldn't understand {command!r}")
match command.split():
- case ["north"] | ["go", "north"]:
+ case NOT_YET_IMPLEMENTED_Pattern:
+ case NOT_YET_IMPLEMENTED_PatternMatchOf | (y):
current_room = current_room.neighbor("north")
- 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
match command.split():
- case ["go", ("north" | "south" | "east" | "west")]:
+ case NOT_YET_IMPLEMENTED_Pattern:
+ case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
current_room = current_room.neighbor(...)
# how do I know which direction to go?
match command.split():
- 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)
match command.split():
- 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)
- case ["go", _]:
+ case NOT_YET_IMPLEMENTED_Pattern:
+ case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
print("Sorry, you can't go that way")
match event.get():
- case Click(position=(x, y)):
+ case NOT_YET_IMPLEMENTED_Pattern:
+ case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
handle_click_at(x, y)
- case KeyPress(key_name="Q") | Quit():
+ case NOT_YET_IMPLEMENTED_Pattern:
+ case NOT_YET_IMPLEMENTED_PatternMatchOf | (y):
game.quit()
- case KeyPress(key_name="up arrow"):
+ case NOT_YET_IMPLEMENTED_Pattern:
+ case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
game.go_north()
- case KeyPress():
+ case NOT_YET_IMPLEMENTED_Pattern:
+ case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
pass # Ignore other keystrokes
- case other_event:
+ case NOT_YET_IMPLEMENTED_Pattern:
+ case x as NOT_YET_IMPLEMENTED_PatternMatchAs:
raise ValueError(f"Unrecognized event: {other_event}")
match event.get():
- 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)
- case Click():
+ case NOT_YET_IMPLEMENTED_Pattern:
+ case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
pass # ignore other clicks
def where_is(point):
match point:
- case Point(x=0, y=0):
+ case NOT_YET_IMPLEMENTED_Pattern:
+ case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
print("Origin")
- case Point(x=0, y=y):
+ case NOT_YET_IMPLEMENTED_Pattern:
+ case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
print(f"Y={y}")
- case Point(x=x, y=0):
+ case NOT_YET_IMPLEMENTED_Pattern:
+ case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
print(f"X={x}")
- case Point():
+ case NOT_YET_IMPLEMENTED_Pattern:
+ case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
print("Somewhere else")
- case _:
+ case NOT_YET_IMPLEMENTED_Pattern:
+ case x as NOT_YET_IMPLEMENTED_PatternMatchAs:
print("Not a point")
```
@ -235,94 +235,94 @@ def where_is(point):
# Cases sampled from PEP 636 examples
match command.split():
case NOT_YET_IMPLEMENTED_Pattern:
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
... # interpret action, obj
match command.split():
case NOT_YET_IMPLEMENTED_Pattern:
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
... # interpret single-verb action
case NOT_YET_IMPLEMENTED_Pattern:
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
... # interpret action, obj
match command.split():
case NOT_YET_IMPLEMENTED_Pattern:
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
print("Goodbye!")
quit_game()
case NOT_YET_IMPLEMENTED_Pattern:
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
current_room.describe()
case NOT_YET_IMPLEMENTED_Pattern:
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
character.get(obj, current_room)
case NOT_YET_IMPLEMENTED_Pattern:
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
current_room = current_room.neighbor(direction)
# The rest of your commands go here
match command.split():
case NOT_YET_IMPLEMENTED_Pattern:
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
for obj in objects:
character.drop(obj, current_room)
# The rest of your commands go here
match command.split():
case NOT_YET_IMPLEMENTED_Pattern:
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
pass
case NOT_YET_IMPLEMENTED_Pattern:
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
print("Going:", direction)
case NOT_YET_IMPLEMENTED_Pattern:
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
print("Dropping: ", *objects)
case NOT_YET_IMPLEMENTED_Pattern:
case x as NOT_YET_IMPLEMENTED_PatternMatchAs:
print(f"Sorry, I couldn't understand {command!r}")
match command.split():
case NOT_YET_IMPLEMENTED_Pattern:
case NOT_YET_IMPLEMENTED_PatternMatchOf | (y):
current_room = current_room.neighbor("north")
case NOT_YET_IMPLEMENTED_Pattern:
case NOT_YET_IMPLEMENTED_PatternMatchOf | (y):
... # Code for picking up the given object
match command.split():
case NOT_YET_IMPLEMENTED_Pattern:
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
current_room = current_room.neighbor(...)
# how do I know which direction to go?
match command.split():
case NOT_YET_IMPLEMENTED_Pattern:
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
current_room = current_room.neighbor(direction)
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)
case NOT_YET_IMPLEMENTED_Pattern:
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
print("Sorry, you can't go that way")
match event.get():
case NOT_YET_IMPLEMENTED_Pattern:
case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
handle_click_at(x, y)
case NOT_YET_IMPLEMENTED_Pattern:
case NOT_YET_IMPLEMENTED_PatternMatchOf | (y):
game.quit()
case NOT_YET_IMPLEMENTED_Pattern:
case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
game.go_north()
case NOT_YET_IMPLEMENTED_Pattern:
case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
pass # Ignore other keystrokes
case NOT_YET_IMPLEMENTED_Pattern:
case x as NOT_YET_IMPLEMENTED_PatternMatchAs:
raise ValueError(f"Unrecognized event: {other_event}")
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)
case NOT_YET_IMPLEMENTED_Pattern:
case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
pass # ignore other clicks
def where_is(point):
match point:
case NOT_YET_IMPLEMENTED_Pattern:
case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
print("Origin")
case NOT_YET_IMPLEMENTED_Pattern:
case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
print(f"Y={y}")
case NOT_YET_IMPLEMENTED_Pattern:
case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
print(f"X={x}")
case NOT_YET_IMPLEMENTED_Pattern:
case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
print("Somewhere else")
case NOT_YET_IMPLEMENTED_Pattern:
case x as NOT_YET_IMPLEMENTED_PatternMatchAs:
print("Not a point")
```

View file

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

View file

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

View file

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

View file

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

View file

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