From 40c5083c759c9e3420932aa082add905bb6950b1 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Fri, 26 Apr 2024 20:03:21 -0700 Subject: [PATCH 1/4] 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"""{''' +'''}""" From aec4fa956fd3f68d7b5fcfd0f8663c14013442f8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 27 Apr 2024 03:04:16 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- CHANGES.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 71da1ff96c1..95422ef70e0 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -25,8 +25,9 @@ ### Parser -- Fix regression where Black failed to parse a multiline f-string containing - another multiline f-string (#4339) + +- Fix regression where Black failed to parse a multiline f-string containing another + multiline f-string (#4339) ### Performance From 2b8fb444911bcc859891b562cc835abb6266d51f Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Fri, 26 Apr 2024 20:05:40 -0700 Subject: [PATCH 3/4] reformat --- src/blib2to3/pgen2/tokenize.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/blib2to3/pgen2/tokenize.py b/src/blib2to3/pgen2/tokenize.py index bac59b75f17..b86b91ed37f 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() in (STATE_NOT_FSTRING, STATE_IN_BRACES) - 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() From 9c0f6c370b29c9f7ee67c520d3f1d02836689549 Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Sat, 27 Apr 2024 01:23:37 -0700 Subject: [PATCH 4/4] Update CHANGES.md --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 95422ef70e0..e3df420b5a0 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -27,7 +27,7 @@ - Fix regression where Black failed to parse a multiline f-string containing another - multiline f-string (#4339) + multiline string (#4339) ### Performance