Clean up dead code in magic trailing comma logic (#4131)
This commit is contained in:
parent
8e0a9dee1b
commit
269190274b
@ -91,7 +91,7 @@ def append(
|
|||||||
if self.mode.magic_trailing_comma:
|
if self.mode.magic_trailing_comma:
|
||||||
if self.has_magic_trailing_comma(leaf):
|
if self.has_magic_trailing_comma(leaf):
|
||||||
self.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()
|
self.remove_trailing_comma()
|
||||||
if not self.append_comment(leaf):
|
if not self.append_comment(leaf):
|
||||||
self.leaves.append(leaf)
|
self.leaves.append(leaf)
|
||||||
@ -342,16 +342,11 @@ def contains_unsplittable_type_ignore(self) -> bool:
|
|||||||
def contains_multiline_strings(self) -> bool:
|
def contains_multiline_strings(self) -> bool:
|
||||||
return any(is_multiline_string(leaf) for leaf in self.leaves)
|
return any(is_multiline_string(leaf) for leaf in self.leaves)
|
||||||
|
|
||||||
def has_magic_trailing_comma(
|
def has_magic_trailing_comma(self, closing: Leaf) -> bool:
|
||||||
self, closing: Leaf, ensure_removable: bool = False
|
|
||||||
) -> bool:
|
|
||||||
"""Return True if we have a magic trailing comma, that is when:
|
"""Return True if we have a magic trailing comma, that is when:
|
||||||
- there's a trailing comma here
|
- 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 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 (
|
if not (
|
||||||
closing.type in CLOSING_BRACKETS
|
closing.type in CLOSING_BRACKETS
|
||||||
@ -375,6 +370,8 @@ def has_magic_trailing_comma(
|
|||||||
brackets=(token.LSQB, token.RSQB),
|
brackets=(token.LSQB, token.RSQB),
|
||||||
)
|
)
|
||||||
):
|
):
|
||||||
|
assert closing.prev_sibling is not None
|
||||||
|
assert closing.prev_sibling.type == syms.subscriptlist
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
Loading…
Reference in New Issue
Block a user