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:
Ran Benita 2023-11-08 06:21:33 +02:00 committed by GitHub
parent 1a7d9c2f58
commit 72e7a2e43e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -353,9 +353,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,
@ -365,22 +365,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