Skip to content

Commit 72e7a2e

Browse files
authored
Remove redundant condition from has_magic_trailing_comma (#4023)
The second `if` cannot be true at its execution point, because it is already covered by the first `if`. The condition `comma.parent.type == syms.subscriptlist` always holds if `closing.parent.type == syms.trailer` holds, because `subscriptlist` only appears inside `trailer` in the grammar: ``` trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME subscriptlist: (subscript|star_expr) (',' (subscript|star_expr))* [','] ```
1 parent 1a7d9c2 commit 72e7a2e

File tree

1 file changed

+3
-18
lines changed

1 file changed

+3
-18
lines changed

src/black/lines.py

+3-18
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,9 @@ def has_magic_trailing_comma(
353353

354354
if closing.type == token.RSQB:
355355
if (
356-
closing.parent
356+
closing.parent is not None
357357
and closing.parent.type == syms.trailer
358-
and closing.opening_bracket
358+
and closing.opening_bracket is not None
359359
and is_one_sequence_between(
360360
closing.opening_bracket,
361361
closing,
@@ -365,22 +365,7 @@ def has_magic_trailing_comma(
365365
):
366366
return False
367367

368-
if not ensure_removable:
369-
return True
370-
371-
comma = self.leaves[-1]
372-
if comma.parent is None:
373-
return False
374-
return (
375-
comma.parent.type != syms.subscriptlist
376-
or closing.opening_bracket is None
377-
or not is_one_sequence_between(
378-
closing.opening_bracket,
379-
closing,
380-
self.leaves,
381-
brackets=(token.LSQB, token.RSQB),
382-
)
383-
)
368+
return True
384369

385370
if self.is_import:
386371
return True

0 commit comments

Comments
 (0)