Don't leave invalid trailing comma on imports

Fixes #185
This commit is contained in:
Łukasz Langa 2018-05-07 10:34:30 -07:00
parent c6a6cfd3a2
commit dc0c14240e
2 changed files with 12 additions and 3 deletions

View File

@ -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

View File

@ -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.