X-Git-Url: https://git.madduck.net/etc/vim.git/blobdiff_plain/e7b967132fdbb9e2e4c4e9916530d238848ab183..4ebf14d17ed544be893be5706c02116fd8b83b4c:/src/black/lines.py?ds=inline diff --git a/src/black/lines.py b/src/black/lines.py index 1ebc780..3062265 100644 --- a/src/black/lines.py +++ b/src/black/lines.py @@ -273,6 +273,8 @@ class Line: - it's not a single-element subscript Additionally, if ensure_removable: - it's not from square bracket indexing + (specifically, single-element square bracket indexing with + Preview.skip_magic_trailing_comma_in_subscript) """ if not ( closing.type in CLOSING_BRACKETS @@ -301,8 +303,22 @@ class Line: if not ensure_removable: return True + comma = self.leaves[-1] - return bool(comma.parent and comma.parent.type == syms.listmaker) + if comma.parent is None: + return False + if Preview.skip_magic_trailing_comma_in_subscript in self.mode: + 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 comma.parent.type == syms.listmaker if self.is_import: return True