Skip to content

Commit

Permalink
Fix another f-string regression
Browse files Browse the repository at this point in the history
  • Loading branch information
JelleZijlstra committed Apr 27, 2024
1 parent dbb956b commit 40c5083
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
### Parser

<!-- Changes to the parser or to version autodetection -->
- Fix regression where Black failed to parse a multiline f-string containing
another multiline f-string (#4339)

### Performance

Expand Down
2 changes: 1 addition & 1 deletion src/blib2to3/pgen2/tokenize.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ def generate_tokens(
epos = (lnum, end)
tokenline = contline + line
if (
fstring_state.current() == STATE_NOT_FSTRING
fstring_state.current() in (STATE_NOT_FSTRING, STATE_IN_BRACES)
and not is_fstring_start(token)
):
yield (STRING, token, spos, epos, tokenline)
Expand Down
6 changes: 6 additions & 0 deletions tests/data/cases/pep_701.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@

f'{{\\"kind\\":\\"ConfigMap\\",\\"metadata\\":{{\\"annotations\\":{{}},\\"name\\":\\"cluster-info\\",\\"namespace\\":\\"amazon-cloudwatch\\"}}}}'

f"""{'''
'''}"""

# output

x = f"foo"
Expand Down Expand Up @@ -252,3 +255,6 @@
f"{1:{2}d}"

f'{{\\"kind\\":\\"ConfigMap\\",\\"metadata\\":{{\\"annotations\\":{{}},\\"name\\":\\"cluster-info\\",\\"namespace\\":\\"amazon-cloudwatch\\"}}}}'

f"""{'''
'''}"""

0 comments on commit 40c5083

Please sign in to comment.