skip_magic_trailing_comma_in_subscript

This commit is contained in:
Jelle Zijlstra 2022-12-10 08:50:37 -08:00
parent 11b0f1e963
commit 0152d51be2
2 changed files with 10 additions and 14 deletions

View File

@ -275,8 +275,7 @@ def has_magic_trailing_comma(
- it's not a single-element subscript - it's not a single-element subscript
Additionally, if ensure_removable: Additionally, if ensure_removable:
- it's not from square bracket indexing - it's not from square bracket indexing
(specifically, single-element square bracket indexing with (specifically, single-element square bracket indexing)
Preview.skip_magic_trailing_comma_in_subscript)
""" """
if not ( if not (
closing.type in CLOSING_BRACKETS closing.type in CLOSING_BRACKETS
@ -308,18 +307,16 @@ def has_magic_trailing_comma(
comma = self.leaves[-1] comma = self.leaves[-1]
if comma.parent is None: if comma.parent is None:
return False return False
if Preview.skip_magic_trailing_comma_in_subscript in self.mode: return (
return ( comma.parent.type != syms.subscriptlist
comma.parent.type != syms.subscriptlist or closing.opening_bracket is None
or closing.opening_bracket is None or not is_one_sequence_between(
or not is_one_sequence_between( closing.opening_bracket,
closing.opening_bracket, closing,
closing, self.leaves,
self.leaves, brackets=(token.LSQB, token.RSQB),
brackets=(token.LSQB, token.RSQB),
)
) )
return comma.parent.type == syms.listmaker )
if self.is_import: if self.is_import:
return True return True

View File

@ -151,7 +151,6 @@ class Preview(Enum):
long_docstring_quotes_on_newline = auto() long_docstring_quotes_on_newline = auto()
string_processing = auto() string_processing = auto()
skip_magic_trailing_comma_in_subscript = auto()
class Deprecated(UserWarning): class Deprecated(UserWarning):