From 817ca26b0e9282e98729bc02ec5ff7420f533909 Mon Sep 17 00:00:00 2001 From: Bryan Bugyi Date: Fri, 6 Nov 2020 18:26:59 -0500 Subject: [PATCH] Fix bug which causes f-expressions to be split 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 e09838d866a..7a7456ad78b 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 9bfb1eedd5a..7065b2fcef8 100644 --- a/tests/data/long_strings__regression.py +++ b/tests/data/long_strings__regression.py @@ -371,6 +371,10 @@ def xxxxxxx_xxxxxx(xxxx): ), } +# 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 @@ def xxxxxxx_xxxxxx(xxxx): r"(?