Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove redundant condition from has_magic_trailing_comma #4023

Merged
merged 2 commits into from Nov 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 3 additions & 18 deletions src/black/lines.py
Expand Up @@ -351,9 +351,9 @@ def has_magic_trailing_comma(

if closing.type == token.RSQB:
if (
closing.parent
closing.parent is not None
and closing.parent.type == syms.trailer
and closing.opening_bracket
and closing.opening_bracket is not None
and is_one_sequence_between(
closing.opening_bracket,
closing,
Expand All @@ -363,22 +363,7 @@ def has_magic_trailing_comma(
):
return False

if not ensure_removable:
return True

comma = self.leaves[-1]
if comma.parent is None:
return False
return (
comma.parent.type != syms.subscriptlist
or closing.opening_bracket is None
or not is_one_sequence_between(
closing.opening_bracket,
closing,
self.leaves,
brackets=(token.LSQB, token.RSQB),
)
)
return True

if self.is_import:
return True
Expand Down