From 40c5083c759c9e3420932aa082add905bb6950b1 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Fri, 26 Apr 2024 20:03:21 -0700 Subject: [PATCH] Fix another f-string regression --- CHANGES.md | 2 ++ src/blib2to3/pgen2/tokenize.py | 2 +- tests/data/cases/pep_701.py | 6 ++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index f56f40f250e..71da1ff96c1 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -25,6 +25,8 @@ ### Parser +- Fix regression where Black failed to parse a multiline f-string containing + another multiline f-string (#4339) ### Performance diff --git a/src/blib2to3/pgen2/tokenize.py b/src/blib2to3/pgen2/tokenize.py index f66087bd0e3..bac59b75f17 100644 --- a/src/blib2to3/pgen2/tokenize.py +++ b/src/blib2to3/pgen2/tokenize.py @@ -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) diff --git a/tests/data/cases/pep_701.py b/tests/data/cases/pep_701.py index 9e157bd6fd1..d72d91c6799 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"""{''' +'''}"""