Fix spurious space after star-based unary expression
This happened when the operand was a complex expression. Fixes #31
This commit is contained in:
parent
9fea478022
commit
22ce1e1fc3
19
black.py
19
black.py
@ -804,6 +804,7 @@ def __attrs_post_init__(self) -> None:
|
||||
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)
|
||||
|
@ -72,6 +72,7 @@
|
||||
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 @@ async def f():
|
||||
kwarg='hey',
|
||||
**kwargs
|
||||
) # note: no trailing comma pre-3.6
|
||||
call(*gidgets[:2])
|
||||
lukasz.langa.pl
|
||||
call.me(maybe)
|
||||
1 .real
|
||||
|
Loading…
Reference in New Issue
Block a user