From edf1c9dc0f20239b9d5351d8b0607c9e936dd43f Mon Sep 17 00:00:00 2001 From: Bryan Bugyi Date: Fri, 6 Nov 2020 19:17:23 -0500 Subject: [PATCH] Fix bug which causes f-expressions to be split (#1809) Closes #1807. --- src/black/__init__.py | 5 +++-- tests/data/long_strings__regression.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/black/__init__.py b/src/black/__init__.py index e09838d..7a7456a 100644 --- a/src/black/__init__.py +++ b/src/black/__init__.py @@ -3611,13 +3611,14 @@ class StringSplitter(CustomSplitMapMixin, BaseStringSplitter): MIN_SUBSTR_SIZE = 6 # Matches an "f-expression" (e.g. {var}) that might be found in an f-string. RE_FEXPR = r""" - (? TMatchResult: diff --git a/tests/data/long_strings__regression.py b/tests/data/long_strings__regression.py index 9bfb1ee..7065b2f 100644 --- a/tests/data/long_strings__regression.py +++ b/tests/data/long_strings__regression.py @@ -371,6 +371,10 @@ RE_THREE_BACKSLASHES = { ), } +# We do NOT split on f-string expressions. +print(f"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam. {[f'{i}' for i in range(10)]}") +x = f"This is a long string which contains an f-expr that should not split {{{[i for i in range(5)]}}}." + # output @@ -830,3 +834,13 @@ RE_THREE_BACKSLASHES = { r"(?