Commit dc0c1424 authored by Łukasz Langa's avatar Łukasz Langa
Browse files

Don't leave invalid trailing comma on imports

Fixes #185
parent c6a6cfd3
Loading
Loading
Loading
Loading
+8 −3
Changes for black.py: 8 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -885,9 +885,14 @@ def maybe_remove_trailing_comma(self, closing: Leaf) -> bool:
                self.remove_trailing_comma()
                return True

        # For parens let's check if it's safe to remove the comma.  If the
        # trailing one is the only one, we might mistakenly change a tuple
        # into a different type by removing the comma.
        # For parens let's check if it's safe to remove the comma.
        # Imports are always safe.
        if self.is_import:
            self.remove_trailing_comma()
            return True

        # Otheriwsse, if the trailing one is the only one, we might mistakenly
        # change a tuple into a different type by removing the comma.
        depth = closing.bracket_depth + 1
        commas = 0
        opening = closing.opening_bracket
+4 −0
Changes for tests/import_spacing.py: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -2,6 +2,9 @@

# flake8: noqa

from logging import (
    ERROR,
)
import sys

# This relies on each of the submodules having an __all__ variable.
@@ -48,6 +51,7 @@

# flake8: noqa

from logging import ERROR
import sys

# This relies on each of the submodules having an __all__ variable.