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))* [','] ```
This commit is contained in:
parent
1a7d9c2f58
commit
72e7a2e43e
@ -353,9 +353,9 @@ def has_magic_trailing_comma(
|
|||||||
|
|
||||||
if closing.type == token.RSQB:
|
if closing.type == token.RSQB:
|
||||||
if (
|
if (
|
||||||
closing.parent
|
closing.parent is not None
|
||||||
and closing.parent.type == syms.trailer
|
and closing.parent.type == syms.trailer
|
||||||
and closing.opening_bracket
|
and closing.opening_bracket is not None
|
||||||
and is_one_sequence_between(
|
and is_one_sequence_between(
|
||||||
closing.opening_bracket,
|
closing.opening_bracket,
|
||||||
closing,
|
closing,
|
||||||
@ -365,22 +365,7 @@ def has_magic_trailing_comma(
|
|||||||
):
|
):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if not ensure_removable:
|
return True
|
||||||
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),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if self.is_import:
|
if self.is_import:
|
||||||
return True
|
return True
|
||||||
|
Loading…
Reference in New Issue
Block a user