Skip to content

Commit

Permalink
Fix another f-string regression (#4339)
Browse files Browse the repository at this point in the history
  • Loading branch information
JelleZijlstra committed Apr 27, 2024
1 parent dbb956b commit 455de77
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Expand Up @@ -26,6 +26,9 @@

<!-- Changes to the parser or to version autodetection -->

- Fix regression where Black failed to parse a multiline f-string containing another
multiline string (#4339)

### Performance

<!-- Changes that improve Black's performance. -->
Expand Down
8 changes: 4 additions & 4 deletions src/blib2to3/pgen2/tokenize.py
Expand Up @@ -622,10 +622,10 @@ def generate_tokens(
spos = strstart
epos = (lnum, end)
tokenline = contline + line
if (
fstring_state.current() == STATE_NOT_FSTRING
and not is_fstring_start(token)
):
if fstring_state.current() in (
STATE_NOT_FSTRING,
STATE_IN_BRACES,
) and not is_fstring_start(token):
yield (STRING, token, spos, epos, tokenline)
endprog_stack.pop()
parenlev = parenlev_stack.pop()
Expand Down
6 changes: 6 additions & 0 deletions tests/data/cases/pep_701.py
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 455de77

Please sign in to comment.