]> 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:

Fix --experiemental-string-processing crash when matching parens not found (#2283)
authorBryan Bugyi <bryanbugyi34@gmail.com>
Sun, 30 May 2021 19:32:28 +0000 (15:32 -0400)
committerGitHub <noreply@github.com>
Sun, 30 May 2021 19:32:28 +0000 (12:32 -0700)
Fixes #2271

CHANGES.md
src/black/trans.py
tests/data/long_strings__regression.py

index d9800a6979c6be0a411e4ba5db1a01ff6339c2aa..63c7a2cf30deb81b9f3207a939b5218244d0cbcc 100644 (file)
@@ -10,6 +10,7 @@
   `.gitignore` rules like `git` does) (#2225)
 - Restored compatibility with Click 8.0 on Python 3.6 when LANG=C used (#2227)
 - Add extra uvloop install + import support if in python env (#2258)
+- Fix --experimental-string-processing crash when matching parens are not found (#2283)
 
 ### _Blackd_
 
index 7ecc31d6d31fbb9d0b3db8c027dd1094f936bbf0..169b675be3d1a84dee8920ded3745556ca1061c9 100644 (file)
@@ -25,7 +25,7 @@ from black.rusty import Result, Ok, Err
 from black.mode import Feature
 from black.nodes import syms, replace_child, parent_type
 from black.nodes import is_empty_par, is_empty_lpar, is_empty_rpar
-from black.nodes import CLOSING_BRACKETS, STANDALONE_COMMENT
+from black.nodes import OPENING_BRACKETS, CLOSING_BRACKETS, STANDALONE_COMMENT
 from black.lines import Line, append_leaves
 from black.brackets import BracketMatchError
 from black.comments import contains_pragma_comment
@@ -1398,6 +1398,11 @@ class StringParenWrapper(CustomSplitMapMixin, BaseStringSplitter):
     def do_splitter_match(self, line: Line) -> TMatchResult:
         LL = line.leaves
 
+        if line.leaves[-1].type in OPENING_BRACKETS:
+            return TErr(
+                "Cannot wrap parens around a line that ends in an opening bracket."
+            )
+
         string_idx = (
             self._return_match(LL)
             or self._else_match(LL)
@@ -1665,9 +1670,10 @@ class StringParenWrapper(CustomSplitMapMixin, BaseStringSplitter):
                 right_leaves.pop()
 
             if old_parens_exist:
-                assert (
-                    right_leaves and right_leaves[-1].type == token.RPAR
-                ), "Apparently, old parentheses do NOT exist?!"
+                assert right_leaves and right_leaves[-1].type == token.RPAR, (
+                    "Apparently, old parentheses do NOT exist?!"
+                    f" (left_leaves={left_leaves}, right_leaves={right_leaves})"
+                )
                 old_rpar_leaf = right_leaves.pop()
 
             append_leaves(string_line, line, right_leaves)
index 2e7f2483b63533ff6822aab807dd4057f7bdfc53..231d88651b656e6e5345537a9993c864facb27aa 100644 (file)
@@ -396,6 +396,16 @@ x = f"This is a long string which contains an f-expr that should not split {{{[i
     " it has now"
 )
 
+
+def _legacy_listen_examples():
+    text += (
+        "    \"listen for the '%(event_name)s' event\"\n"
+        "\n    # ... (event logic logic logic) ...\n"
+        % {
+            "since": since,
+        }
+    )
+
 # output
 
 
@@ -886,3 +896,13 @@ x = (
     " it goes over 88 characters which"
     " it has now"
 )
+
+
+def _legacy_listen_examples():
+    text += (
+        "    \"listen for the '%(event_name)s' event\"\n"
+        "\n    # ... (event logic logic logic) ...\n"
+        % {
+            "since": since,
+        }
+    )