]> git.madduck.net Git - etc/vim.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Don't introduce quotes to f-string sub-expressions on string boundaries (#871)
authorZsolt Dollenstein <zsol.zsol@gmail.com>
Sun, 26 May 2019 09:58:00 +0000 (11:58 +0200)
committerGitHub <noreply@github.com>
Sun, 26 May 2019 09:58:00 +0000 (11:58 +0200)
README.md
black.py
tests/data/string_quotes.py

index ead7b61e12a1700b1488259939f128bfeef20862..9d8310101af882fa600dce91daea5e8df79408c0 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1034,6 +1034,9 @@ More details can be found in [CONTRIBUTING](CONTRIBUTING.md).
 * fixed bug that led *Black* format some code with a line length target
   of 1 (#762)
 
+* *Black* no longer introduces quotes in f-string subexpressions on string
+  boundaries (#863)
+
 
 ### 19.3b0
 
index 7ede0b45f7908a11a453654a8d17145df60481f9..7629d9f4c2d23f09e45b16fdf83eb82f3bbf99a1 100644 (file)
--- a/black.py
+++ b/black.py
@@ -2728,7 +2728,15 @@ def normalize_string_quotes(leaf: Leaf) -> None:
         new_body = sub_twice(escaped_orig_quote, rf"\1\2{orig_quote}", new_body)
         new_body = sub_twice(unescaped_new_quote, rf"\1\\{new_quote}", new_body)
     if "f" in prefix.casefold():
-        matches = re.findall(r"[^{]\{(.*?)\}[^}]", new_body)
+        matches = re.findall(
+            r"""
+            (?:[^{]|^)\{  # start of the string or a non-{ followed by a single {
+                ([^{].*?)  # contents of the brackets except if begins with {{
+            \}(?:[^}]|$)  # A } followed by end of the string or a non-}
+            """,
+            new_body,
+            re.VERBOSE,
+        )
         for m in matches:
             if "\\" in str(m):
                 # Do not introduce backslashes in interpolated expressions
index 1994dd273d92b5a9936ab22f76492a2bc1347141..6b68699c42219c276f7de037ebb4414599a5bba8 100644 (file)
@@ -44,6 +44,12 @@ re.compile(r'[\\"]')
 '\\""'
 "\\''"
 'Lots of \\\\\\\\\'quotes\''
+f'{y * " "} \'{z}\''
+f'{{y * " "}} \'{z}\''
+f'\'{z}\' {y * " "}'
+f'{y * x} \'{z}\''
+'\'{z}\' {y * " "}'
+'{y * x} \'{z}\''
 
 # output
 
@@ -93,3 +99,9 @@ re.compile(r'[\\"]')
 '\\""'
 "\\''"
 "Lots of \\\\\\\\'quotes'"
+f'{y * " "} \'{z}\''
+f"{{y * \" \"}} '{z}'"
+f'\'{z}\' {y * " "}'
+f"{y * x} '{z}'"
+"'{z}' {y * \" \"}"
+"{y * x} '{z}'"
\ No newline at end of file