mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-01 08:07:31 +00:00
Disallow f-strings in match pattern literal (#7857)
## Summary This PR fixes a bug to disallow f-strings in match pattern literal. ``` literal_pattern ::= signed_number | signed_number "+" NUMBER | signed_number "-" NUMBER | strings | "None" | "True" | "False" | signed_number: NUMBER | "-" NUMBER ``` Source: https://docs.python.org/3/reference/compound_stmts.html#grammar-token-python-grammar-literal_pattern Also, ```console $ python /tmp/t.py File "/tmp/t.py", line 4 case "hello " f"{name}": ^^^^^^^^^^^^^^^^^^ SyntaxError: patterns may only match literals and attribute lookups ``` ## Test Plan Update existing test case and accordingly the snapshots. Also, add a new test case to verify that the parser does raise an error.
This commit is contained in:
parent
38f512d588
commit
43883b7a15
4 changed files with 13901 additions and 13810 deletions
|
@ -668,7 +668,7 @@ LiteralPattern: ast::Pattern = {
|
|||
value: Box::new(value.into()),
|
||||
range: (location..end_location).into()
|
||||
}.into(),
|
||||
<location:@L> <strings:StringLiteralOrFString+> <end_location:@R> =>? Ok(ast::PatternMatchValue {
|
||||
<location:@L> <strings:StringLiteral+> <end_location:@R> =>? Ok(ast::PatternMatchValue {
|
||||
value: Box::new(concatenate_strings(strings, (location..end_location).into())?),
|
||||
range: (location..end_location).into()
|
||||
}.into()),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue