Fix another f-string regression (#4339)

This commit is contained in:
Jelle Zijlstra 2024-04-27 01:24:20 -07:00 committed by GitHub
parent dbb956b0d3
commit 455de7703e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 4 deletions

View File

@ -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. -->

View File

@ -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()

View File

@ -125,6 +125,9 @@
f'{{\\"kind\\":\\"ConfigMap\\",\\"metadata\\":{{\\"annotations\\":{{}},\\"name\\":\\"cluster-info\\",\\"namespace\\":\\"amazon-cloudwatch\\"}}}}'
f"""{'''
'''}"""
# output
x = f"foo"
@ -252,3 +255,6 @@
f"{1:{2}d}"
f'{{\\"kind\\":\\"ConfigMap\\",\\"metadata\\":{{\\"annotations\\":{{}},\\"name\\":\\"cluster-info\\",\\"namespace\\":\\"amazon-cloudwatch\\"}}}}'
f"""{'''
'''}"""