Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# parse_options: {"target-version": "3.15"}
match value:
case -1**2: ...
case -1 .real: ...
case -1[0]: ...
case -1(): ...
case {+1**2: _}: ...
20 changes: 20 additions & 0 deletions crates/ruff_python_parser/src/parser/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,26 @@ impl Parser<'_> {
ExpressionContext::default(),
);

// test_err signed_pattern_non_literal_operand
// # parse_options: {"target-version": "3.15"}
// match value:
// case -1**2: ...
// case -1 .real: ...
// case -1[0]: ...
// case -1(): ...
// case {+1**2: _}: ...

// Parse the full operand for error recovery, but only numeric literals
// are valid after a sign in a literal pattern.
if !unary_expr.operand.is_number_literal_expr() {
self.add_error(
ParseErrorType::OtherError(
"Expected a numeric literal after unary operator".to_string(),
),
unary_expr.operand.range(),
);
}

// test_ok unary_plus_py315
// # parse_options: {"target-version": "3.15"}
// match foo:
Expand Down
Loading
Loading