Add trailing comma for single as imports, too

This commit is contained in:
Łukasz Langa 2018-09-26 08:26:35 -07:00
parent 0c5c537431
commit 1610fd6bc5
No known key found for this signature in database
GPG Key ID: B26995E310250568
4 changed files with 27 additions and 2 deletions

View File

@ -2329,8 +2329,9 @@ def bracket_split_build_line(
# Since body is a new indent level, remove spurious leading whitespace.
normalize_prefix(leaves[0], inside_brackets=True)
# Ensure a trailing comma when expected.
if original.is_import and len(leaves) == 1:
leaves.append(Leaf(token.COMMA, ","))
if original.is_import:
if leaves[-1].type != token.COMMA:
leaves.append(Leaf(token.COMMA, ","))
# Populate the line
for leaf in leaves:
result.append(leaf, preformatted=True)

View File

@ -79,6 +79,8 @@ Parsing
Split functions
---------------
.. autofunction:: black.bracket_split_build_line
.. autofunction:: black.bracket_split_succeeded_or_raise
.. autofunction:: black.delimiter_split

View File

@ -1,3 +1,10 @@
from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import (
MyLovelyCompanyTeamProjectComponent # NOT DRY
)
from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import (
MyLovelyCompanyTeamProjectComponent as component # DRY
)
# Please keep __all__ alphabetized within each category.
__all__ = [
@ -148,6 +155,13 @@ def inline_comments_in_brackets_ruin_everything():
# output
from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import (
MyLovelyCompanyTeamProjectComponent, # NOT DRY
)
from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import (
MyLovelyCompanyTeamProjectComponent as component, # DRY
)
# Please keep __all__ alphabetized within each category.
__all__ = [

View File

@ -1,3 +1,11 @@
from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import (
MyLovelyCompanyTeamProjectComponent, # NOT DRY
)
from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import (
MyLovelyCompanyTeamProjectComponent as component, # DRY
)
class C:
@pytest.mark.parametrize(
("post_data", "message"),