From: Ɓukasz Langa Date: Mon, 7 May 2018 17:34:30 +0000 (-0700) Subject: Don't leave invalid trailing comma on imports X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/dc0c14240e7423d9ada002835dcc195f8c6d8797 Don't leave invalid trailing comma on imports Fixes #185 --- diff --git a/black.py b/black.py index 4675456..fd2b75e 100644 --- a/black.py +++ b/black.py @@ -885,9 +885,14 @@ class Line: 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 diff --git a/tests/import_spacing.py b/tests/import_spacing.py index f095ba1..cc17405 100644 --- a/tests/import_spacing.py +++ b/tests/import_spacing.py @@ -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 @@ __all__ = ( # flake8: noqa +from logging import ERROR import sys # This relies on each of the submodules having an __all__ variable.