diff --git a/CHANGES.md b/CHANGES.md index f56f40f..e3df420 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -26,6 +26,9 @@ +- Fix regression where Black failed to parse a multiline f-string containing another + multiline string (#4339) + ### Performance diff --git a/src/blib2to3/pgen2/tokenize.py b/src/blib2to3/pgen2/tokenize.py index f66087b..b86b91e 100644 --- a/src/blib2to3/pgen2/tokenize.py +++ b/src/blib2to3/pgen2/tokenize.py @@ -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() diff --git a/tests/data/cases/pep_701.py b/tests/data/cases/pep_701.py index 9e157bd..d72d91c 100644 --- a/tests/data/cases/pep_701.py +++ b/tests/data/cases/pep_701.py @@ -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"""{''' +'''}"""