mirror of
https://github.com/astral-sh/ruff.git
synced 2025-12-10 03:31:26 +00:00
Format PatternMatchSequence (#6676)
This commit is contained in:
parent
c34a342ab4
commit
94f5f18ddb
9 changed files with 353 additions and 143 deletions
|
|
@ -172,6 +172,7 @@ match x:
|
||||||
case (a as b) as c:
|
case (a as b) as c:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
match pattern_singleton:
|
match pattern_singleton:
|
||||||
case (
|
case (
|
||||||
# leading 1
|
# leading 1
|
||||||
|
|
@ -187,3 +188,30 @@ match pattern_singleton:
|
||||||
...
|
...
|
||||||
case False:
|
case False:
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
|
match foo:
|
||||||
|
case "a", "b":
|
||||||
|
pass
|
||||||
|
case "a", "b",:
|
||||||
|
pass
|
||||||
|
case ("a", "b"):
|
||||||
|
pass
|
||||||
|
case ["a", "b"]:
|
||||||
|
pass
|
||||||
|
case (["a", "b"]):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
match foo:
|
||||||
|
case [ # leading
|
||||||
|
# leading
|
||||||
|
# leading
|
||||||
|
# leading
|
||||||
|
"a", # trailing
|
||||||
|
# trailing
|
||||||
|
# trailing
|
||||||
|
# trailing
|
||||||
|
"b",
|
||||||
|
]:
|
||||||
|
pass
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,53 @@
|
||||||
use ruff_formatter::{write, Buffer, FormatResult};
|
use ruff_formatter::prelude::format_with;
|
||||||
|
use ruff_formatter::{Format, FormatResult};
|
||||||
use ruff_python_ast::PatternMatchSequence;
|
use ruff_python_ast::PatternMatchSequence;
|
||||||
|
|
||||||
use crate::{not_yet_implemented_custom_text, FormatNodeRule, PyFormatter};
|
use crate::builders::PyFormatterExtensions;
|
||||||
|
use crate::expression::parentheses::{empty_parenthesized, optional_parentheses, parenthesized};
|
||||||
|
use crate::{FormatNodeRule, PyFormatter};
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct FormatPatternMatchSequence;
|
pub struct FormatPatternMatchSequence;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
enum SequenceType {
|
||||||
|
Tuple,
|
||||||
|
TupleNoParens,
|
||||||
|
List,
|
||||||
|
}
|
||||||
|
|
||||||
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!(
|
let PatternMatchSequence { patterns, range } = item;
|
||||||
f,
|
let sequence_type = match &f.context().source()[*range].chars().next() {
|
||||||
[not_yet_implemented_custom_text(
|
Some('(') => SequenceType::Tuple,
|
||||||
"[NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]",
|
Some('[') => SequenceType::List,
|
||||||
item
|
_ => SequenceType::TupleNoParens,
|
||||||
)]
|
};
|
||||||
)
|
let comments = f.context().comments().clone();
|
||||||
|
let dangling = comments.dangling(item);
|
||||||
|
if patterns.is_empty() {
|
||||||
|
return match sequence_type {
|
||||||
|
SequenceType::Tuple => empty_parenthesized("(", dangling, ")").fmt(f),
|
||||||
|
SequenceType::List => empty_parenthesized("[", dangling, "]").fmt(f),
|
||||||
|
SequenceType::TupleNoParens => {
|
||||||
|
unreachable!("If empty, it should be either tuple or list")
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
let items = format_with(|f| {
|
||||||
|
f.join_comma_separated(range.end())
|
||||||
|
.nodes(patterns.iter())
|
||||||
|
.finish()
|
||||||
|
});
|
||||||
|
match sequence_type {
|
||||||
|
SequenceType::Tuple => parenthesized("(", &items, ")")
|
||||||
|
.with_dangling_comments(dangling)
|
||||||
|
.fmt(f),
|
||||||
|
SequenceType::List => parenthesized("[", &items, "]")
|
||||||
|
.with_dangling_comments(dangling)
|
||||||
|
.fmt(f),
|
||||||
|
SequenceType::TupleNoParens => optional_parentheses(&items).fmt(f),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -156,7 +156,7 @@ match x:
|
||||||
```diff
|
```diff
|
||||||
--- Black
|
--- Black
|
||||||
+++ Ruff
|
+++ Ruff
|
||||||
@@ -2,105 +2,105 @@
|
@@ -2,97 +2,108 @@
|
||||||
|
|
||||||
# case black_test_patma_098
|
# case black_test_patma_098
|
||||||
match x:
|
match x:
|
||||||
|
|
@ -189,7 +189,7 @@ match x:
|
||||||
# case black_check_sequence_then_mapping
|
# case black_check_sequence_then_mapping
|
||||||
match x:
|
match x:
|
||||||
- case [*_]:
|
- case [*_]:
|
||||||
+ case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
+ case [*NOT_YET_IMPLEMENTED_PatternMatchStar]:
|
||||||
return "seq"
|
return "seq"
|
||||||
- case {}:
|
- case {}:
|
||||||
+ case {"NOT_YET_IMPLEMENTED_PatternMatchMapping": _, 2: _}:
|
+ case {"NOT_YET_IMPLEMENTED_PatternMatchMapping": _, 2: _}:
|
||||||
|
|
@ -202,8 +202,7 @@ match x:
|
||||||
- case {0: [1, 2, {}] | True} | {1: [[]]} | {0: [1, 2, {}]} | [] | "X" | {}:
|
- case {0: [1, 2, {}] | True} | {1: [[]]} | {0: [1, 2, {}]} | [] | "X" | {}:
|
||||||
+ case NOT_YET_IMPLEMENTED_PatternMatchOf | (y):
|
+ case NOT_YET_IMPLEMENTED_PatternMatchOf | (y):
|
||||||
y = 1
|
y = 1
|
||||||
- case []:
|
case []:
|
||||||
+ case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
|
||||||
y = 2
|
y = 2
|
||||||
# case black_test_patma_107
|
# case black_test_patma_107
|
||||||
match x:
|
match x:
|
||||||
|
|
@ -239,7 +238,7 @@ match x:
|
||||||
# case black_test_patma_185
|
# case black_test_patma_185
|
||||||
match Seq():
|
match Seq():
|
||||||
- case [*_]:
|
- case [*_]:
|
||||||
+ case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
+ case [*NOT_YET_IMPLEMENTED_PatternMatchStar]:
|
||||||
y = 0
|
y = 0
|
||||||
# case black_test_patma_063
|
# case black_test_patma_063
|
||||||
match x:
|
match x:
|
||||||
|
|
@ -257,23 +256,34 @@ match x:
|
||||||
# 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_PatternMatchSequence, 2]:
|
+ case [
|
||||||
|
+ "NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
+ "NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
+ *NOT_YET_IMPLEMENTED_PatternMatchStar,
|
||||||
|
+ "NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
+ ]:
|
||||||
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_PatternMatchSequence, 2]:
|
+ case ["NOT_YET_IMPLEMENTED_PatternMatchValue"]:
|
||||||
y = 0
|
y = 0
|
||||||
- case [1, 0] if (x := x[:0]):
|
- case [1, 0] if (x := x[:0]):
|
||||||
+ case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2] if (x := x[:0]):
|
+ case [
|
||||||
|
+ "NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
+ "NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
+ ] if (x := x[:0]):
|
||||||
y = 1
|
y = 1
|
||||||
- case [1, 0]:
|
- case [1, 0]:
|
||||||
+ case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
+ case [
|
||||||
|
+ "NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
+ "NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
+ ]:
|
||||||
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_PatternMatchSequence, 2]:
|
+ case [x, y, *NOT_YET_IMPLEMENTED_PatternMatchStar]:
|
||||||
z = 0
|
z = 0
|
||||||
# case black_test_patma_110
|
# case black_test_patma_110
|
||||||
match x:
|
match x:
|
||||||
|
|
@ -282,8 +292,7 @@ match x:
|
||||||
y = 0
|
y = 0
|
||||||
# case black_test_patma_151
|
# case black_test_patma_151
|
||||||
match (x,):
|
match (x,):
|
||||||
- case [y]:
|
@@ -100,7 +111,7 @@
|
||||||
+ case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
|
||||||
z = 0
|
z = 0
|
||||||
# case black_test_patma_114
|
# case black_test_patma_114
|
||||||
match x:
|
match x:
|
||||||
|
|
@ -292,7 +301,7 @@ match x:
|
||||||
y = 0
|
y = 0
|
||||||
# case black_test_patma_232
|
# case black_test_patma_232
|
||||||
match x:
|
match x:
|
||||||
@@ -108,7 +108,7 @@
|
@@ -108,7 +119,7 @@
|
||||||
y = 0
|
y = 0
|
||||||
# case black_test_patma_058
|
# case black_test_patma_058
|
||||||
match x:
|
match x:
|
||||||
|
|
@ -301,27 +310,24 @@ match x:
|
||||||
y = 0
|
y = 0
|
||||||
# case black_test_patma_233
|
# case black_test_patma_233
|
||||||
match x:
|
match x:
|
||||||
@@ -116,11 +116,11 @@
|
@@ -118,9 +129,9 @@
|
||||||
y = 0
|
|
||||||
# case black_test_patma_078
|
|
||||||
match x:
|
match x:
|
||||||
- case []:
|
case []:
|
||||||
+ case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
|
||||||
y = 0
|
y = 0
|
||||||
- case [""]:
|
- case [""]:
|
||||||
+ case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
+ case ["NOT_YET_IMPLEMENTED_PatternMatchValue"]:
|
||||||
y = 1
|
y = 1
|
||||||
- case "":
|
- case "":
|
||||||
+ case "NOT_YET_IMPLEMENTED_PatternMatchValue":
|
+ case "NOT_YET_IMPLEMENTED_PatternMatchValue":
|
||||||
y = 2
|
y = 2
|
||||||
# case black_test_patma_156
|
# case black_test_patma_156
|
||||||
match x:
|
match x:
|
||||||
@@ -128,17 +128,17 @@
|
@@ -128,17 +139,17 @@
|
||||||
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_PatternMatchSequence, 2]:
|
+ case [x, y, *NOT_YET_IMPLEMENTED_PatternMatchStar]:
|
||||||
z = 0
|
z = 0
|
||||||
# case black_test_patma_042
|
# case black_test_patma_042
|
||||||
match x:
|
match x:
|
||||||
|
|
@ -336,8 +342,7 @@ match x:
|
||||||
- case {0: [1, 2, {}] | False} | {1: [[]]} | {0: [1, 2, {}]} | [] | "X" | {}:
|
- case {0: [1, 2, {}] | False} | {1: [[]]} | {0: [1, 2, {}]} | [] | "X" | {}:
|
||||||
+ case NOT_YET_IMPLEMENTED_PatternMatchOf | (y):
|
+ case NOT_YET_IMPLEMENTED_PatternMatchOf | (y):
|
||||||
y = 1
|
y = 1
|
||||||
- case []:
|
case []:
|
||||||
+ case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
|
||||||
y = 2
|
y = 2
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -370,7 +375,7 @@ match x:
|
||||||
y = 0
|
y = 0
|
||||||
# case black_check_sequence_then_mapping
|
# case black_check_sequence_then_mapping
|
||||||
match x:
|
match x:
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case [*NOT_YET_IMPLEMENTED_PatternMatchStar]:
|
||||||
return "seq"
|
return "seq"
|
||||||
case {"NOT_YET_IMPLEMENTED_PatternMatchMapping": _, 2: _}:
|
case {"NOT_YET_IMPLEMENTED_PatternMatchMapping": _, 2: _}:
|
||||||
return "map"
|
return "map"
|
||||||
|
|
@ -380,7 +385,7 @@ match x:
|
||||||
y = 0
|
y = 0
|
||||||
case NOT_YET_IMPLEMENTED_PatternMatchOf | (y):
|
case NOT_YET_IMPLEMENTED_PatternMatchOf | (y):
|
||||||
y = 1
|
y = 1
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case []:
|
||||||
y = 2
|
y = 2
|
||||||
# case black_test_patma_107
|
# case black_test_patma_107
|
||||||
match x:
|
match x:
|
||||||
|
|
@ -408,7 +413,7 @@ match x:
|
||||||
y = 2
|
y = 2
|
||||||
# case black_test_patma_185
|
# case black_test_patma_185
|
||||||
match Seq():
|
match Seq():
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case [*NOT_YET_IMPLEMENTED_PatternMatchStar]:
|
||||||
y = 0
|
y = 0
|
||||||
# case black_test_patma_063
|
# case black_test_patma_063
|
||||||
match x:
|
match x:
|
||||||
|
|
@ -422,19 +427,30 @@ match x:
|
||||||
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_PatternMatchSequence, 2]:
|
case [
|
||||||
|
"NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
"NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
*NOT_YET_IMPLEMENTED_PatternMatchStar,
|
||||||
|
"NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
]:
|
||||||
y = 0
|
y = 0
|
||||||
# case black_test_patma_052
|
# case black_test_patma_052
|
||||||
match x:
|
match x:
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case ["NOT_YET_IMPLEMENTED_PatternMatchValue"]:
|
||||||
y = 0
|
y = 0
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2] if (x := x[:0]):
|
case [
|
||||||
|
"NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
"NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
] if (x := x[:0]):
|
||||||
y = 1
|
y = 1
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case [
|
||||||
|
"NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
"NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
]:
|
||||||
y = 2
|
y = 2
|
||||||
# case black_test_patma_191
|
# case black_test_patma_191
|
||||||
match w:
|
match w:
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case [x, y, *NOT_YET_IMPLEMENTED_PatternMatchStar]:
|
||||||
z = 0
|
z = 0
|
||||||
# case black_test_patma_110
|
# case black_test_patma_110
|
||||||
match x:
|
match x:
|
||||||
|
|
@ -442,7 +458,7 @@ match x:
|
||||||
y = 0
|
y = 0
|
||||||
# case black_test_patma_151
|
# case black_test_patma_151
|
||||||
match (x,):
|
match (x,):
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case [y]:
|
||||||
z = 0
|
z = 0
|
||||||
# case black_test_patma_114
|
# case black_test_patma_114
|
||||||
match x:
|
match x:
|
||||||
|
|
@ -462,9 +478,9 @@ match x:
|
||||||
y = 0
|
y = 0
|
||||||
# case black_test_patma_078
|
# case black_test_patma_078
|
||||||
match x:
|
match x:
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case []:
|
||||||
y = 0
|
y = 0
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case ["NOT_YET_IMPLEMENTED_PatternMatchValue"]:
|
||||||
y = 1
|
y = 1
|
||||||
case "NOT_YET_IMPLEMENTED_PatternMatchValue":
|
case "NOT_YET_IMPLEMENTED_PatternMatchValue":
|
||||||
y = 2
|
y = 2
|
||||||
|
|
@ -474,7 +490,7 @@ match x:
|
||||||
y = 0
|
y = 0
|
||||||
# case black_test_patma_189
|
# case black_test_patma_189
|
||||||
match w:
|
match w:
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case [x, y, *NOT_YET_IMPLEMENTED_PatternMatchStar]:
|
||||||
z = 0
|
z = 0
|
||||||
# case black_test_patma_042
|
# case black_test_patma_042
|
||||||
match x:
|
match x:
|
||||||
|
|
@ -486,7 +502,7 @@ match x:
|
||||||
y = 0
|
y = 0
|
||||||
case NOT_YET_IMPLEMENTED_PatternMatchOf | (y):
|
case NOT_YET_IMPLEMENTED_PatternMatchOf | (y):
|
||||||
y = 1
|
y = 1
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case []:
|
||||||
y = 2
|
y = 2
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -131,15 +131,9 @@ match bar1:
|
||||||
```diff
|
```diff
|
||||||
--- Black
|
--- Black
|
||||||
+++ Ruff
|
+++ Ruff
|
||||||
@@ -1,13 +1,13 @@
|
@@ -5,9 +5,9 @@
|
||||||
import match
|
|
||||||
|
|
||||||
match something:
|
|
||||||
- case [a as b]:
|
|
||||||
+ 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_PatternMatchSequence, 2]:
|
|
||||||
print(f)
|
print(f)
|
||||||
- case Point(a as b):
|
- case Point(a as b):
|
||||||
+ case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
|
+ case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
|
||||||
|
|
@ -158,7 +152,7 @@ match bar1:
|
||||||
pass
|
pass
|
||||||
case match:
|
case match:
|
||||||
pass
|
pass
|
||||||
@@ -23,32 +23,35 @@
|
@@ -23,32 +23,47 @@
|
||||||
|
|
||||||
def func(match: case, case: match) -> case:
|
def func(match: case, case: match) -> case:
|
||||||
match Something():
|
match Something():
|
||||||
|
|
@ -171,10 +165,13 @@ match bar1:
|
||||||
|
|
||||||
match maybe, multiple:
|
match maybe, multiple:
|
||||||
- case perhaps, 5:
|
- case perhaps, 5:
|
||||||
+ case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
+ case perhaps, "NOT_YET_IMPLEMENTED_PatternMatchValue":
|
||||||
pass
|
pass
|
||||||
- case perhaps, 6,:
|
- case perhaps, 6,:
|
||||||
+ case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
+ case (
|
||||||
|
+ perhaps,
|
||||||
|
+ "NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
+ ):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -184,10 +181,19 @@ match bar1:
|
||||||
+ more := (than, one),
|
+ more := (than, one),
|
||||||
+ indeed,
|
+ indeed,
|
||||||
+):
|
+):
|
||||||
+ case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
+ case _, (
|
||||||
|
+ "NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
+ "NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
+ ):
|
||||||
pass
|
pass
|
||||||
- case [[5], (6)], [7],:
|
- case [[5], (6)], [7],:
|
||||||
+ case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
+ case [
|
||||||
|
+ [
|
||||||
|
+ ["NOT_YET_IMPLEMENTED_PatternMatchValue"],
|
||||||
|
+ "NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
+ ],
|
||||||
|
+ ["NOT_YET_IMPLEMENTED_PatternMatchValue"],
|
||||||
|
+ ]:
|
||||||
pass
|
pass
|
||||||
case _:
|
case _:
|
||||||
pass
|
pass
|
||||||
|
|
@ -195,14 +201,14 @@ match bar1:
|
||||||
|
|
||||||
match a, *b, c:
|
match a, *b, c:
|
||||||
- case [*_]:
|
- case [*_]:
|
||||||
+ case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
+ case [*NOT_YET_IMPLEMENTED_PatternMatchStar]:
|
||||||
assert "seq" == _
|
assert "seq" == _
|
||||||
- case {}:
|
- case {}:
|
||||||
+ case {"NOT_YET_IMPLEMENTED_PatternMatchMapping": _, 2: _}:
|
+ case {"NOT_YET_IMPLEMENTED_PatternMatchMapping": _, 2: _}:
|
||||||
assert "map" == b
|
assert "map" == b
|
||||||
|
|
||||||
|
|
||||||
@@ -59,15 +62,10 @@
|
@@ -59,12 +74,7 @@
|
||||||
),
|
),
|
||||||
case,
|
case,
|
||||||
):
|
):
|
||||||
|
|
@ -215,17 +221,13 @@ match bar1:
|
||||||
+ case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
|
+ case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
- case [a as match]:
|
case [a as match]:
|
||||||
+ case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
@@ -80,40 +90,43 @@
|
||||||
pass
|
|
||||||
|
|
||||||
case case:
|
|
||||||
@@ -80,40 +78,35 @@
|
|
||||||
|
|
||||||
|
|
||||||
match a, *b(), c:
|
match a, *b(), c:
|
||||||
- case d, *f, g:
|
- case d, *f, g:
|
||||||
+ case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
+ case d, *NOT_YET_IMPLEMENTED_PatternMatchStar, g:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -247,11 +249,19 @@ match bar1:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
- case 2 as b, 3 as c:
|
- case 2 as b, 3 as c:
|
||||||
+ case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
+ case (
|
||||||
|
+ "NOT_YET_IMPLEMENTED_PatternMatchValue" as b,
|
||||||
|
+ "NOT_YET_IMPLEMENTED_PatternMatchValue" as c,
|
||||||
|
+ ):
|
||||||
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_PatternMatchSequence, 2]:
|
+ case (
|
||||||
|
+ "NOT_YET_IMPLEMENTED_PatternMatchValue" as d,
|
||||||
|
+ "NOT_YET_IMPLEMENTED_PatternMatchValue" as e,
|
||||||
|
+ NOT_YET_IMPLEMENTED_PatternMatchOf | (y) as g,
|
||||||
|
+ *NOT_YET_IMPLEMENTED_PatternMatchStar,
|
||||||
|
+ ):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -277,9 +287,9 @@ match bar1:
|
||||||
import match
|
import match
|
||||||
|
|
||||||
match something:
|
match something:
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case [a as b]:
|
||||||
print(b)
|
print(b)
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case [a as b, c, d, e as f]:
|
||||||
print(f)
|
print(f)
|
||||||
case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
|
case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
|
||||||
print(b)
|
print(b)
|
||||||
|
|
@ -306,9 +316,12 @@ def func(match: case, case: match) -> case:
|
||||||
|
|
||||||
|
|
||||||
match maybe, multiple:
|
match maybe, multiple:
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case perhaps, "NOT_YET_IMPLEMENTED_PatternMatchValue":
|
||||||
pass
|
pass
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case (
|
||||||
|
perhaps,
|
||||||
|
"NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -316,16 +329,25 @@ match (
|
||||||
more := (than, one),
|
more := (than, one),
|
||||||
indeed,
|
indeed,
|
||||||
):
|
):
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case _, (
|
||||||
|
"NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
"NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
):
|
||||||
pass
|
pass
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case [
|
||||||
|
[
|
||||||
|
["NOT_YET_IMPLEMENTED_PatternMatchValue"],
|
||||||
|
"NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
],
|
||||||
|
["NOT_YET_IMPLEMENTED_PatternMatchValue"],
|
||||||
|
]:
|
||||||
pass
|
pass
|
||||||
case _:
|
case _:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
match a, *b, c:
|
match a, *b, c:
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case [*NOT_YET_IMPLEMENTED_PatternMatchStar]:
|
||||||
assert "seq" == _
|
assert "seq" == _
|
||||||
case {"NOT_YET_IMPLEMENTED_PatternMatchMapping": _, 2: _}:
|
case {"NOT_YET_IMPLEMENTED_PatternMatchMapping": _, 2: _}:
|
||||||
assert "map" == b
|
assert "map" == b
|
||||||
|
|
@ -341,7 +363,7 @@ match match(
|
||||||
case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
|
case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case [a as match]:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
case case:
|
case case:
|
||||||
|
|
@ -354,7 +376,7 @@ match match:
|
||||||
|
|
||||||
|
|
||||||
match a, *b(), c:
|
match a, *b(), c:
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case d, *NOT_YET_IMPLEMENTED_PatternMatchStar, g:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -369,10 +391,18 @@ match something:
|
||||||
case "NOT_YET_IMPLEMENTED_PatternMatchValue" as a:
|
case "NOT_YET_IMPLEMENTED_PatternMatchValue" as a:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case (
|
||||||
|
"NOT_YET_IMPLEMENTED_PatternMatchValue" as b,
|
||||||
|
"NOT_YET_IMPLEMENTED_PatternMatchValue" as c,
|
||||||
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case (
|
||||||
|
"NOT_YET_IMPLEMENTED_PatternMatchValue" as d,
|
||||||
|
"NOT_YET_IMPLEMENTED_PatternMatchValue" as e,
|
||||||
|
NOT_YET_IMPLEMENTED_PatternMatchOf | (y) as g,
|
||||||
|
*NOT_YET_IMPLEMENTED_PatternMatchStar,
|
||||||
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,7 @@ with match() as match:
|
||||||
y = 0
|
y = 0
|
||||||
self.assertIs(x, False)
|
self.assertIs(x, False)
|
||||||
self.assertEqual(y, 0)
|
self.assertEqual(y, 0)
|
||||||
@@ -73,14 +73,14 @@
|
@@ -73,7 +73,7 @@
|
||||||
x = 0
|
x = 0
|
||||||
y = None
|
y = None
|
||||||
match x:
|
match x:
|
||||||
|
|
@ -137,14 +137,6 @@ with match() as match:
|
||||||
y = 0
|
y = 0
|
||||||
self.assertEqual(x, 0)
|
self.assertEqual(x, 0)
|
||||||
self.assertIs(y, None)
|
self.assertIs(y, None)
|
||||||
|
|
||||||
x = range(3)
|
|
||||||
match x:
|
|
||||||
- case [y, case as x, z]:
|
|
||||||
+ case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
|
||||||
w = 0
|
|
||||||
|
|
||||||
# At least one of the above branches must have been taken, because every Python
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Ruff Output
|
## Ruff Output
|
||||||
|
|
@ -232,7 +224,7 @@ def get_grammars(target_versions: Set[TargetVersion]) -> List[Grammar]:
|
||||||
|
|
||||||
x = range(3)
|
x = range(3)
|
||||||
match x:
|
match x:
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case [y, case as x, z]:
|
||||||
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
|
||||||
|
|
|
||||||
|
|
@ -104,54 +104,47 @@ def where_is(point):
|
||||||
```diff
|
```diff
|
||||||
--- Black
|
--- Black
|
||||||
+++ Ruff
|
+++ Ruff
|
||||||
@@ -1,92 +1,92 @@
|
@@ -11,82 +11,97 @@
|
||||||
# Cases sampled from PEP 636 examples
|
|
||||||
|
|
||||||
match command.split():
|
|
||||||
- case [action, obj]:
|
|
||||||
+ case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
|
||||||
... # interpret action, obj
|
|
||||||
|
|
||||||
match command.split():
|
|
||||||
- case [action]:
|
|
||||||
+ case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
|
||||||
... # interpret single-verb action
|
|
||||||
- case [action, obj]:
|
|
||||||
+ 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_PatternMatchSequence, 2]:
|
+ case ["NOT_YET_IMPLEMENTED_PatternMatchValue"]:
|
||||||
print("Goodbye!")
|
print("Goodbye!")
|
||||||
quit_game()
|
quit_game()
|
||||||
- case ["look"]:
|
- case ["look"]:
|
||||||
+ case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
+ case ["NOT_YET_IMPLEMENTED_PatternMatchValue"]:
|
||||||
current_room.describe()
|
current_room.describe()
|
||||||
- case ["get", obj]:
|
- case ["get", obj]:
|
||||||
+ case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
+ case ["NOT_YET_IMPLEMENTED_PatternMatchValue", obj]:
|
||||||
character.get(obj, current_room)
|
character.get(obj, current_room)
|
||||||
- case ["go", direction]:
|
- case ["go", direction]:
|
||||||
+ case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
+ case ["NOT_YET_IMPLEMENTED_PatternMatchValue", direction]:
|
||||||
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_PatternMatchSequence, 2]:
|
+ case [
|
||||||
|
+ "NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
+ *NOT_YET_IMPLEMENTED_PatternMatchStar,
|
||||||
|
+ ]:
|
||||||
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_PatternMatchSequence, 2]:
|
+ case ["NOT_YET_IMPLEMENTED_PatternMatchValue"]:
|
||||||
pass
|
pass
|
||||||
- case ["go", direction]:
|
- case ["go", direction]:
|
||||||
+ case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
+ case ["NOT_YET_IMPLEMENTED_PatternMatchValue", direction]:
|
||||||
print("Going:", direction)
|
print("Going:", direction)
|
||||||
- case ["drop", *objects]:
|
- case ["drop", *objects]:
|
||||||
+ case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
+ case [
|
||||||
|
+ "NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
+ *NOT_YET_IMPLEMENTED_PatternMatchStar,
|
||||||
|
+ ]:
|
||||||
print("Dropping: ", *objects)
|
print("Dropping: ", *objects)
|
||||||
case _:
|
case _:
|
||||||
print(f"Sorry, I couldn't understand {command!r}")
|
print(f"Sorry, I couldn't understand {command!r}")
|
||||||
|
|
@ -166,21 +159,30 @@ def where_is(point):
|
||||||
|
|
||||||
match command.split():
|
match command.split():
|
||||||
- case ["go", ("north" | "south" | "east" | "west")]:
|
- case ["go", ("north" | "south" | "east" | "west")]:
|
||||||
+ case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
+ case [
|
||||||
|
+ "NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
+ NOT_YET_IMPLEMENTED_PatternMatchOf | (y),
|
||||||
|
+ ]:
|
||||||
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_PatternMatchSequence, 2]:
|
+ case [
|
||||||
|
+ "NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
+ NOT_YET_IMPLEMENTED_PatternMatchOf | (y) as direction,
|
||||||
|
+ ]:
|
||||||
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_PatternMatchSequence, 2] if direction in current_room.exits:
|
+ case [
|
||||||
|
+ "NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
+ direction,
|
||||||
|
+ ] 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_PatternMatchSequence, 2]:
|
+ case ["NOT_YET_IMPLEMENTED_PatternMatchValue", _]:
|
||||||
print("Sorry, you can't go that way")
|
print("Sorry, you can't go that way")
|
||||||
|
|
||||||
match event.get():
|
match event.get():
|
||||||
|
|
@ -232,39 +234,45 @@ 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_PatternMatchSequence, 2]:
|
case [action, obj]:
|
||||||
... # interpret action, obj
|
... # interpret action, obj
|
||||||
|
|
||||||
match command.split():
|
match command.split():
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case [action]:
|
||||||
... # interpret single-verb action
|
... # interpret single-verb action
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case [action, obj]:
|
||||||
... # interpret action, obj
|
... # interpret action, obj
|
||||||
|
|
||||||
match command.split():
|
match command.split():
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case ["NOT_YET_IMPLEMENTED_PatternMatchValue"]:
|
||||||
print("Goodbye!")
|
print("Goodbye!")
|
||||||
quit_game()
|
quit_game()
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case ["NOT_YET_IMPLEMENTED_PatternMatchValue"]:
|
||||||
current_room.describe()
|
current_room.describe()
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case ["NOT_YET_IMPLEMENTED_PatternMatchValue", obj]:
|
||||||
character.get(obj, current_room)
|
character.get(obj, current_room)
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case ["NOT_YET_IMPLEMENTED_PatternMatchValue", direction]:
|
||||||
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_PatternMatchSequence, 2]:
|
case [
|
||||||
|
"NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
*NOT_YET_IMPLEMENTED_PatternMatchStar,
|
||||||
|
]:
|
||||||
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_PatternMatchSequence, 2]:
|
case ["NOT_YET_IMPLEMENTED_PatternMatchValue"]:
|
||||||
pass
|
pass
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case ["NOT_YET_IMPLEMENTED_PatternMatchValue", direction]:
|
||||||
print("Going:", direction)
|
print("Going:", direction)
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case [
|
||||||
|
"NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
*NOT_YET_IMPLEMENTED_PatternMatchStar,
|
||||||
|
]:
|
||||||
print("Dropping: ", *objects)
|
print("Dropping: ", *objects)
|
||||||
case _:
|
case _:
|
||||||
print(f"Sorry, I couldn't understand {command!r}")
|
print(f"Sorry, I couldn't understand {command!r}")
|
||||||
|
|
@ -276,18 +284,27 @@ match command.split():
|
||||||
... # Code for picking up the given object
|
... # Code for picking up the given object
|
||||||
|
|
||||||
match command.split():
|
match command.split():
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case [
|
||||||
|
"NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
NOT_YET_IMPLEMENTED_PatternMatchOf | (y),
|
||||||
|
]:
|
||||||
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_PatternMatchSequence, 2]:
|
case [
|
||||||
|
"NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
NOT_YET_IMPLEMENTED_PatternMatchOf | (y) as direction,
|
||||||
|
]:
|
||||||
current_room = current_room.neighbor(direction)
|
current_room = current_room.neighbor(direction)
|
||||||
|
|
||||||
match command.split():
|
match command.split():
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2] if direction in current_room.exits:
|
case [
|
||||||
|
"NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
direction,
|
||||||
|
] if direction in current_room.exits:
|
||||||
current_room = current_room.neighbor(direction)
|
current_room = current_room.neighbor(direction)
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case ["NOT_YET_IMPLEMENTED_PatternMatchValue", _]:
|
||||||
print("Sorry, you can't go that way")
|
print("Sorry, you can't go that way")
|
||||||
|
|
||||||
match event.get():
|
match event.get():
|
||||||
|
|
|
||||||
|
|
@ -97,11 +97,11 @@ def http_error(status):
|
||||||
match point:
|
match point:
|
||||||
case (0, 0): # fmt: skip
|
case (0, 0): # fmt: skip
|
||||||
print("Origin")
|
print("Origin")
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case ("NOT_YET_IMPLEMENTED_PatternMatchValue", y):
|
||||||
print(f"Y={y}")
|
print(f"Y={y}")
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case (x, "NOT_YET_IMPLEMENTED_PatternMatchValue"):
|
||||||
print(f"X={x}")
|
print(f"X={x}")
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case (x, y):
|
||||||
print(f"X={x}, Y={y}")
|
print(f"X={x}, Y={y}")
|
||||||
case _:
|
case _:
|
||||||
raise ValueError("Not a point")
|
raise ValueError("Not a point")
|
||||||
|
|
@ -127,15 +127,18 @@ def location(point):
|
||||||
|
|
||||||
|
|
||||||
match points:
|
match points:
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case []:
|
||||||
print("No points in the list.")
|
print("No points in the list.")
|
||||||
case [
|
case [
|
||||||
Point(0, 0)
|
Point(0, 0)
|
||||||
]: # fmt: skip
|
]: # fmt: skip
|
||||||
print("The origin is the only point in the list.")
|
print("The origin is the only point in the list.")
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case [NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0)]:
|
||||||
print(f"A single point {x}, {y} is in the list.")
|
print(f"A single point {x}, {y} is in the list.")
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case [
|
||||||
|
NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0),
|
||||||
|
NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0),
|
||||||
|
]:
|
||||||
print(f"Two points on the Y axis at {y1}, {y2} are in the list.")
|
print(f"Two points on the Y axis at {y1}, {y2} are in the list.")
|
||||||
case _:
|
case _:
|
||||||
print("Something else is found in the list.")
|
print("Something else is found in the list.")
|
||||||
|
|
@ -148,7 +151,7 @@ match test_variable:
|
||||||
40
|
40
|
||||||
): # fmt: skip
|
): # fmt: skip
|
||||||
print("A warning has been received.")
|
print("A warning has been received.")
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case ("NOT_YET_IMPLEMENTED_PatternMatchValue", code, _):
|
||||||
print(f"An error {code} occurred.")
|
print(f"An error {code} occurred.")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -142,7 +142,8 @@ match ( # d 2
|
||||||
case d2:
|
case d2:
|
||||||
pass
|
pass
|
||||||
match d3:
|
match d3:
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case ( # d 3
|
||||||
|
):
|
||||||
pass
|
pass
|
||||||
while ( # d 4
|
while ( # d 4
|
||||||
):
|
):
|
||||||
|
|
|
||||||
|
|
@ -178,6 +178,7 @@ match x:
|
||||||
case (a as b) as c:
|
case (a as b) as c:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
match pattern_singleton:
|
match pattern_singleton:
|
||||||
case (
|
case (
|
||||||
# leading 1
|
# leading 1
|
||||||
|
|
@ -193,6 +194,33 @@ match pattern_singleton:
|
||||||
...
|
...
|
||||||
case False:
|
case False:
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
|
match foo:
|
||||||
|
case "a", "b":
|
||||||
|
pass
|
||||||
|
case "a", "b",:
|
||||||
|
pass
|
||||||
|
case ("a", "b"):
|
||||||
|
pass
|
||||||
|
case ["a", "b"]:
|
||||||
|
pass
|
||||||
|
case (["a", "b"]):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
match foo:
|
||||||
|
case [ # leading
|
||||||
|
# leading
|
||||||
|
# leading
|
||||||
|
# leading
|
||||||
|
"a", # trailing
|
||||||
|
# trailing
|
||||||
|
# trailing
|
||||||
|
# trailing
|
||||||
|
"b",
|
||||||
|
]:
|
||||||
|
pass
|
||||||
```
|
```
|
||||||
|
|
||||||
## Output
|
## Output
|
||||||
|
|
@ -226,13 +254,21 @@ match [ # comment
|
||||||
second,
|
second,
|
||||||
third,
|
third,
|
||||||
]: # another comment
|
]: # another comment
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case [
|
||||||
|
"NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
"NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
"NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
]:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
match ( # comment
|
match ( # comment
|
||||||
"a b c"
|
"a b c"
|
||||||
).split(): # another comment
|
).split(): # another comment
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case [
|
||||||
|
"NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
"NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
"NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
]:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -240,7 +276,11 @@ match ( # comment
|
||||||
# let's go
|
# let's go
|
||||||
yield foo
|
yield foo
|
||||||
): # another comment
|
): # another comment
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2]:
|
case [
|
||||||
|
"NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
"NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
"NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
]:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -268,7 +308,10 @@ match newlines:
|
||||||
case "NOT_YET_IMPLEMENTED_PatternMatchValue" if foo == 2: # second
|
case "NOT_YET_IMPLEMENTED_PatternMatchValue" if foo == 2: # second
|
||||||
pass
|
pass
|
||||||
|
|
||||||
case [NOT_YET_IMPLEMENTED_PatternMatchSequence, 2] if (foo := 1): # third
|
case (
|
||||||
|
"NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
"NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
) if (foo := 1): # third
|
||||||
pass
|
pass
|
||||||
|
|
||||||
case "NOT_YET_IMPLEMENTED_PatternMatchValue":
|
case "NOT_YET_IMPLEMENTED_PatternMatchValue":
|
||||||
|
|
@ -360,6 +403,7 @@ match x:
|
||||||
case (a as b) as c:
|
case (a as b) as c:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
match pattern_singleton:
|
match pattern_singleton:
|
||||||
case (
|
case (
|
||||||
# leading 1
|
# leading 1
|
||||||
|
|
@ -375,6 +419,51 @@ match pattern_singleton:
|
||||||
...
|
...
|
||||||
case False:
|
case False:
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
|
match foo:
|
||||||
|
case (
|
||||||
|
"NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
"NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
case (
|
||||||
|
"NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
"NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
case (
|
||||||
|
"NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
"NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
case [
|
||||||
|
"NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
"NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
]:
|
||||||
|
pass
|
||||||
|
case (
|
||||||
|
[
|
||||||
|
"NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
"NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
]
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
match foo:
|
||||||
|
case [
|
||||||
|
# leading
|
||||||
|
# leading
|
||||||
|
# leading
|
||||||
|
# leading
|
||||||
|
"NOT_YET_IMPLEMENTED_PatternMatchValue", # trailing
|
||||||
|
# trailing
|
||||||
|
# trailing
|
||||||
|
# trailing
|
||||||
|
"NOT_YET_IMPLEMENTED_PatternMatchValue",
|
||||||
|
]:
|
||||||
|
pass
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue