From dc0c14240e7423d9ada002835dcc195f8c6d8797 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C5=81ukasz=20Langa?= Date: Mon, 7 May 2018 10:34:30 -0700 Subject: [PATCH 1/1] Don't leave invalid trailing comma on imports Fixes #185 --- black.py | 11 ++++++++--- tests/import_spacing.py | 4 ++++ 2 files changed, 12 insertions(+), 3 deletions(-) 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. -- 2.39.5