]> 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 fail the entire right_hand_split if an optional split failed
authorŁukasz Langa <lukasz@langa.pl>
Tue, 8 May 2018 01:46:16 +0000 (18:46 -0700)
committerŁukasz Langa <lukasz@langa.pl>
Tue, 8 May 2018 17:11:16 +0000 (10:11 -0700)
Fixes splitting long import lines with only a single name.

.flake8
README.md
black.py
tests/import_spacing.py

diff --git a/.flake8 b/.flake8
index fae93b09498fcb080a830bbb8a0cc2a3007f861a..c286ad0c15dff1a3fcd779d0b0e220b6b7455185 100644 (file)
--- a/.flake8
+++ b/.flake8
@@ -4,5 +4,5 @@
 [flake8]
 ignore = E203, E266, E501, W503
 max-line-length = 80
 [flake8]
 ignore = E203, E266, E501, W503
 max-line-length = 80
-max-complexity = 15
+max-complexity = 18
 select = B,C,E,F,W,T4,B9
 select = B,C,E,F,W,T4,B9
index 30990590403a52158789e1953f2bc522a64dcf06..a9ec9eab86167fd7f4ce39cc4076bf456ec023ca 100644 (file)
--- a/README.md
+++ b/README.md
@@ -547,6 +547,8 @@ More details can be found in [CONTRIBUTING](CONTRIBUTING.md).
 * fixed non-deterministic formatting when multiple pairs of removable parentheses
   were used (#183)
 
 * fixed non-deterministic formatting when multiple pairs of removable parentheses
   were used (#183)
 
+* fixed not splitting long from-imports with only a single name
+
 
 ### 18.4a4
 
 
 ### 18.4a4
 
index c10eb39f10666ddd6622c47ee16a0dcca4f26d17..d2d23c879420d24e945e95fbccd1e578edf436a8 100644 (file)
--- a/black.py
+++ b/black.py
@@ -41,7 +41,7 @@ from blib2to3 import pygram, pytree
 from blib2to3.pgen2 import driver, token
 from blib2to3.pgen2.parse import ParseError
 
 from blib2to3.pgen2 import driver, token
 from blib2to3.pgen2.parse import ParseError
 
-__version__ = "18.4a5"
+__version__ = "18.4a6"
 DEFAULT_LINE_LENGTH = 88
 
 # types
 DEFAULT_LINE_LENGTH = 88
 
 # types
@@ -1830,7 +1830,8 @@ def left_hand_split(line: Line, py36: bool = False) -> Iterator[Line]:
     """Split line into many lines, starting with the first matching bracket pair.
 
     Note: this usually looks weird, only use this for function definitions.
     """Split line into many lines, starting with the first matching bracket pair.
 
     Note: this usually looks weird, only use this for function definitions.
-    Prefer RHS otherwise.
+    Prefer RHS otherwise.  This is why this function is not symmetrical with
+    :func:`right_hand_split` which also handles optional parentheses.
     """
     head = Line(depth=line.depth)
     body = Line(depth=line.depth + 1, inside_brackets=True)
     """
     head = Line(depth=line.depth)
     body = Line(depth=line.depth + 1, inside_brackets=True)
@@ -1870,7 +1871,10 @@ def left_hand_split(line: Line, py36: bool = False) -> Iterator[Line]:
 def right_hand_split(
     line: Line, py36: bool = False, omit: Collection[LeafID] = ()
 ) -> Iterator[Line]:
 def right_hand_split(
     line: Line, py36: bool = False, omit: Collection[LeafID] = ()
 ) -> Iterator[Line]:
-    """Split line into many lines, starting with the last matching bracket pair."""
+    """Split line into many lines, starting with the last matching bracket pair.
+
+    If the split was by optional parentheses, attempt splitting without them, too.
+    """
     head = Line(depth=line.depth)
     body = Line(depth=line.depth + 1, inside_brackets=True)
     tail = Line(depth=line.depth)
     head = Line(depth=line.depth)
     body = Line(depth=line.depth + 1, inside_brackets=True)
     tail = Line(depth=line.depth)
@@ -1909,20 +1913,25 @@ def right_hand_split(
     bracket_split_succeeded_or_raise(head, body, tail)
     assert opening_bracket and closing_bracket
     if (
     bracket_split_succeeded_or_raise(head, body, tail)
     assert opening_bracket and closing_bracket
     if (
+        # the opening bracket is an optional paren
         opening_bracket.type == token.LPAR
         and not opening_bracket.value
         opening_bracket.type == token.LPAR
         and not opening_bracket.value
+        # the closing bracket is an optional paren
         and closing_bracket.type == token.RPAR
         and not closing_bracket.value
         and closing_bracket.type == token.RPAR
         and not closing_bracket.value
+        # there are no delimiters or standalone comments in the body
+        and not body.bracket_tracker.delimiters
+        and not line.contains_standalone_comments(0)
+        # and it's not an import (optional parens are the only thing we can split
+        # on in this case; attempting a split without them is a waste of time)
+        and not line.is_import
     ):
     ):
-        # These parens were optional. If there aren't any delimiters or standalone
-        # comments in the body, they were unnecessary and another split without
-        # them should be attempted.
-        if not (
-            body.bracket_tracker.delimiters or line.contains_standalone_comments(0)
-        ):
-            omit = {id(closing_bracket), *omit}
+        omit = {id(closing_bracket), *omit}
+        try:
             yield from right_hand_split(line, py36=py36, omit=omit)
             return
             yield from right_hand_split(line, py36=py36, omit=omit)
             return
+        except CannotSplit:
+            pass
 
     ensure_visible(opening_bracket)
     ensure_visible(closing_bracket)
 
     ensure_visible(opening_bracket)
     ensure_visible(closing_bracket)
index cc17405aa3a6486b3c05e1985fc808a1ab41e76f..cefa1e96754b105857d4f397282c84b25ec41be9 100644 (file)
@@ -23,6 +23,7 @@ from ..streams import *
 from some_library import (
     Just, Enough, Libraries, To, Fit, In, This, Nice, Split, Which, We, No, Longer, Use
 )
 from some_library import (
     Just, Enough, Libraries, To, Fit, In, This, Nice, Split, Which, We, No, Longer, Use
 )
+from name_of_a_company.extremely_long_project_name.component.ttypes import CuteLittleServiceHandlerFactoryyy
 
 from .a.b.c.subprocess import *
 from . import (tasks)
 
 from .a.b.c.subprocess import *
 from . import (tasks)
@@ -83,6 +84,9 @@ from some_library import (
     Longer,
     Use,
 )
     Longer,
     Use,
 )
+from name_of_a_company.extremely_long_project_name.component.ttypes import (
+    CuteLittleServiceHandlerFactoryyy
+)
 
 from .a.b.c.subprocess import *
 from . import tasks
 
 from .a.b.c.subprocess import *
 from . import tasks