From: Ɓukasz Langa Date: Fri, 16 Mar 2018 06:56:30 +0000 (-0700) Subject: Fix spurious space after star-based unary expression X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/22ce1e1fc389869696f8cfc5627b8b1b322308b4?ds=sidebyside;hp=9fea4780228dc8e9ceb53ddb18fe1a87f6e05546 Fix spurious space after star-based unary expression This happened when the operand was a complex expression. Fixes #31 --- diff --git a/black.py b/black.py index d011483..39f25d3 100644 --- a/black.py +++ b/black.py @@ -804,6 +804,7 @@ BRACKET = {token.LPAR: token.RPAR, token.LSQB: token.RSQB, token.LBRACE: token.R OPENING_BRACKETS = set(BRACKET.keys()) CLOSING_BRACKETS = set(BRACKET.values()) BRACKETS = OPENING_BRACKETS | CLOSING_BRACKETS +ALWAYS_NO_SPACE = CLOSING_BRACKETS | {token.COMMA, token.COLON, STANDALONE_COMMENT} def whitespace(leaf: Leaf) -> str: @@ -814,24 +815,12 @@ def whitespace(leaf: Leaf) -> str: t = leaf.type p = leaf.parent v = leaf.value - if t == token.COLON: - return NO - - if t == token.COMMA: - return NO - - if t == token.RPAR: + if t in ALWAYS_NO_SPACE: return NO if t == token.COMMENT: return DOUBLESPACE - if t == STANDALONE_COMMENT: - return NO - - if t in CLOSING_BRACKETS: - return NO - assert p is not None, f"INTERNAL ERROR: hand-made leaf without parent: {leaf!r}" prev = leaf.prev_sibling if not prev: @@ -863,7 +852,7 @@ def whitespace(leaf: Leaf) -> str: if prevp.parent and prevp.parent.type == syms.subscript: return NO - elif prevp.parent and prevp.parent.type == syms.factor: + elif prevp.parent and prevp.parent.type in {syms.factor, syms.star_expr}: return NO elif prev.type in OPENING_BRACKETS: @@ -992,7 +981,7 @@ def whitespace(leaf: Leaf) -> str: if prev.type == token.DOUBLESTAR: return NO - elif p.type == syms.factor or p.type == syms.star_expr: + elif p.type in {syms.factor, syms.star_expr}: # unary ops if not prev: prevp = preceding_leaf(p) diff --git a/tests/expression.py b/tests/expression.py index 30a20e9..2e7f275 100644 --- a/tests/expression.py +++ b/tests/expression.py @@ -72,6 +72,7 @@ call(kwarg='hey') call(arg, kwarg='hey') call(arg, another, kwarg='hey', **kwargs) call(this_is_a_very_long_variable_which_will_force_a_delimiter_split, arg, another, kwarg='hey', **kwargs) # note: no trailing comma pre-3.6 +call(*gidgets[:2]) lukasz.langa.pl call.me(maybe) 1 .real @@ -204,6 +205,7 @@ call( kwarg='hey', **kwargs ) # note: no trailing comma pre-3.6 +call(*gidgets[:2]) lukasz.langa.pl call.me(maybe) 1 .real