From 199e3eb76b74d9d2cada527403a3989287c4e8b3 Mon Sep 17 00:00:00 2001 From: Bryan Bugyi Date: Sun, 30 May 2021 18:34:33 -0400 Subject: [PATCH 1/1] Fix regular expression that black uses to identify f-expressions (#2287) Fixes #1469 --- CHANGES.md | 1 + src/black/trans.py | 4 ++-- tests/data/long_strings__regression.py | 12 ++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index c761d14..3925698 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,7 @@ - Add extra uvloop install + import support if in python env (#2258) - Fix --experimental-string-processing crash when matching parens are not found (#2283) - Make sure to split lines that start with a string operator (#2286) +- Fix regular expression that black uses to identify f-expressions (#2287) ### _Blackd_ diff --git a/src/black/trans.py b/src/black/trans.py index 80e88a2..fd0de72 100644 --- a/src/black/trans.py +++ b/src/black/trans.py @@ -971,8 +971,8 @@ class StringSplitter(CustomSplitMapMixin, BaseStringSplitter): | \{\{ | \}\} | (?R) - )+? - (? TMatchResult: diff --git a/tests/data/long_strings__regression.py b/tests/data/long_strings__regression.py index bd7b635..cd8053f 100644 --- a/tests/data/long_strings__regression.py +++ b/tests/data/long_strings__regression.py @@ -407,6 +407,12 @@ def _legacy_listen_examples(): ) +temp_msg = ( + f"{f'{humanize_number(pos)}.': <{pound_len+2}} " + f"{balance: <{bal_len + 5}} " + f"<<{author.display_name}>>\n" +) + assert str(suffix_arr) == ( "['$', 'angaroo$', 'angrykangaroo$', 'aroo$', 'garoo$', " "'grykangaroo$', 'kangaroo$', 'ngaroo$', 'ngrykangaroo$', " @@ -942,6 +948,12 @@ def _legacy_listen_examples(): ) +temp_msg = ( + f"{f'{humanize_number(pos)}.': <{pound_len+2}} " + f"{balance: <{bal_len + 5}} " + f"<<{author.display_name}>>\n" +) + assert ( str(suffix_arr) == "['$', 'angaroo$', 'angrykangaroo$', 'aroo$', 'garoo$', " -- 2.39.5