ruff/crates/ruff_python_parser/src
Dhruv Manilawala 43883b7a15
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.
2023-10-09 10:11:08 +00:00
..
lexer Add support for PEP 701 (#7376) 2023-09-29 02:55:39 +00:00
snapshots Disallow f-strings in match pattern literal (#7857) 2023-10-09 10:11:08 +00:00
context.rs Remove Parse trait (#6235) 2023-08-01 18:35:03 +02:00
function.rs Move Ranged into ruff_text_size (#6919) 2023-08-27 14:12:51 -04:00
lexer.rs Fix lexing single-quoted f-string with multi-line format spec (#7787) 2023-10-05 23:12:09 +05:30
lib.rs Skip all bracketed expressions when locating comparison ops (#7740) 2023-10-01 14:57:40 +00:00
parser.rs Disallow f-strings in match pattern literal (#7857) 2023-10-09 10:11:08 +00:00
python.lalrpop Disallow f-strings in match pattern literal (#7857) 2023-10-09 10:11:08 +00:00
python.rs Disallow f-strings in match pattern literal (#7857) 2023-10-09 10:11:08 +00:00
soft_keywords.rs Replace .map_or(false, $closure) with .is_some_and(closure) (#6244) 2023-08-01 19:29:42 +02:00
string.rs Remove escaped mac/windows eol from AST string value (#7724) 2023-10-01 07:37:59 +05:30
token.rs Add support for PEP 701 (#7376) 2023-09-29 02:55:39 +00:00
typing.rs Replace .map_or(false, $closure) with .is_some_and(closure) (#6244) 2023-08-01 19:29:42 +02:00