diff --git a/src/black/lines.py b/src/black/lines.py index 0c3f166..b544c5e 100644 --- a/src/black/lines.py +++ b/src/black/lines.py @@ -91,7 +91,7 @@ def append( if self.mode.magic_trailing_comma: if self.has_magic_trailing_comma(leaf): self.magic_trailing_comma = leaf - elif self.has_magic_trailing_comma(leaf, ensure_removable=True): + elif self.has_magic_trailing_comma(leaf): self.remove_trailing_comma() if not self.append_comment(leaf): self.leaves.append(leaf) @@ -342,16 +342,11 @@ def contains_unsplittable_type_ignore(self) -> bool: def contains_multiline_strings(self) -> bool: return any(is_multiline_string(leaf) for leaf in self.leaves) - def has_magic_trailing_comma( - self, closing: Leaf, ensure_removable: bool = False - ) -> bool: + def has_magic_trailing_comma(self, closing: Leaf) -> bool: """Return True if we have a magic trailing comma, that is when: - there's a trailing comma here + - it's not from single-element square bracket indexing - it's not a one-tuple - - it's not a single-element subscript - Additionally, if ensure_removable: - - it's not from square bracket indexing - (specifically, single-element square bracket indexing) """ if not ( closing.type in CLOSING_BRACKETS @@ -375,6 +370,8 @@ def has_magic_trailing_comma( brackets=(token.LSQB, token.RSQB), ) ): + assert closing.prev_sibling is not None + assert closing.prev_sibling.type == syms.subscriptlist return False return True