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

Add trailing comma when a single import doesn't fit on a line. (#504)
authorZsolt Dollenstein <zsol.zsol@gmail.com>
Wed, 26 Sep 2018 12:26:50 +0000 (13:26 +0100)
committerŁukasz Langa <lukasz@langa.pl>
Wed, 26 Sep 2018 12:26:50 +0000 (13:26 +0100)
Fixes #250.

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

index b56af4ab5baa3413548ee79f7e7579d2c1c99177..192f47ebe682d920ab0f2c6b46afcc6ffbaffe70 100644 (file)
--- a/README.md
+++ b/README.md
@@ -964,6 +964,8 @@ More details can be found in [CONTRIBUTING](CONTRIBUTING.md).
   to be a bad idea (#415)
 
 
   to be a bad idea (#415)
 
 
+* trailing comma is now added to single imports that don't fit on a line (#250)
+
 
 ### 18.6b4
 
 
 ### 18.6b4
 
index 56765313aa85b0571c7831f209573bd2b3fbb955..f76f0ffc24cfcf237d13fcc19f5492635158c4c4 100644 (file)
--- a/black.py
+++ b/black.py
@@ -2209,7 +2209,7 @@ def left_hand_split(line: Line, py36: bool = False) -> Iterator[Line]:
             yield result
 
 
             yield result
 
 
-def right_hand_split(
+def right_hand_split(  # noqa C901
     line: Line, line_length: int, py36: bool = False, omit: Collection[LeafID] = ()
 ) -> Iterator[Line]:
     """Split line into many lines, starting with the last matching bracket pair.
     line: Line, line_length: int, py36: bool = False, omit: Collection[LeafID] = ()
 ) -> Iterator[Line]:
     """Split line into many lines, starting with the last matching bracket pair.
@@ -2250,6 +2250,9 @@ def right_hand_split(
         # the matching `opening_bracket` wasn't available on `line` anymore.
         raise CannotSplit("No brackets found")
 
         # the matching `opening_bracket` wasn't available on `line` anymore.
         raise CannotSplit("No brackets found")
 
+    if line.is_import and len(body_leaves) == 1:
+        body_leaves.append(Leaf(token.COMMA, ","))
+
     # Build the new lines.
     for result, leaves in (head, head_leaves), (body, body_leaves), (tail, tail_leaves):
         for leaf in leaves:
     # Build the new lines.
     for result, leaves in (head, head_leaves), (body, body_leaves), (tail, tail_leaves):
         for leaf in leaves:
index 0c98650f8339c56728442cdca93345d268c045c7..51cfda23ff355fa430e0a652d845283bfc6ac13d 100644 (file)
@@ -86,7 +86,7 @@ from some_library import (
     Use,
 )
 from name_of_a_company.extremely_long_project_name.component.ttypes import (
     Use,
 )
 from name_of_a_company.extremely_long_project_name.component.ttypes import (
-    CuteLittleServiceHandlerFactoryyy
+    CuteLittleServiceHandlerFactoryyy,
 )
 from name_of_a_company.extremely_long_project_name.extremely_long_component_name.ttypes import *
 
 )
 from name_of_a_company.extremely_long_project_name.extremely_long_component_name.ttypes import *