]> git.madduck.net Git - etc/vim.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Fix spurious space after star-based unary expression
authorŁukasz Langa <lukasz@langa.pl>
Fri, 16 Mar 2018 06:56:30 +0000 (23:56 -0700)
committerŁukasz Langa <lukasz@langa.pl>
Fri, 16 Mar 2018 06:56:30 +0000 (23:56 -0700)
This happened when the operand was a complex expression.

Fixes #31

black.py
tests/expression.py

index d011483747546de1b3248dff21a88b52f9ad4649..39f25d3eb73058a4b28cb14e48ede96266cc89fe 100644 (file)
--- 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)
index 30a20e977045fa7743765cf32df71813fdd6a36f..2e7f2750e7dd2e3ea934b3da26d6330cf727dac6 100644 (file)
@@ -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