Skip to content

Commit

Permalink
Add trailing comma when a single import doesn't fit on a line.
Browse files Browse the repository at this point in the history
Fixes #250.
  • Loading branch information
zsol committed Sep 8, 2018
1 parent 25795c9 commit 230e872
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion black.py
Expand Up @@ -2174,7 +2174,7 @@ def left_hand_split(line: Line, py36: bool = False) -> Iterator[Line]:
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.
Expand Down Expand Up @@ -2215,6 +2215,9 @@ def right_hand_split(
# 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:
Expand Down
2 changes: 1 addition & 1 deletion tests/data/import_spacing.py
Expand Up @@ -86,7 +86,7 @@
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 *

Expand Down

0 comments on commit 230e872

Please sign in to comment.