Commit 92b37755 authored by Łukasz Langa's avatar Łukasz Langa
Browse files

Don't omit whitespace when the factor is not a math operator

Fixes #55
parent c7c8c4f5
Loading
Loading
Loading
Loading
+5 −0
Changes for README.md: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -293,6 +293,11 @@ More details can be found in [CONTRIBUTING](CONTRIBUTING.md).

## Change Log

### 18.3a4 (unreleased)

* don't omit whitespace if the previous factor leaf wasn't a math
  operator (#55)

### 18.3a3

* don't remove single empty lines outside of bracketed expressions
+6 −1
Changes for black.py: 6 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -340,6 +340,7 @@ def visit_default(self, node: LN) -> Iterator[T]:
    token.AMPER,
    token.PERCENT,
    token.CIRCUMFLEX,
    token.TILDE,
    token.LEFTSHIFT,
    token.RIGHTSHIFT,
    token.DOUBLESTAR,
@@ -888,7 +889,11 @@ def whitespace(leaf: Leaf) -> str: # noqa C901
            if prevp.parent and prevp.parent.type in {syms.subscript, syms.sliceop}:
                return NO

        elif prevp.parent and prevp.parent.type in {syms.factor, syms.star_expr}:
        elif (
            prevp.parent
            and prevp.parent.type in {syms.factor, syms.star_expr}
            and prevp.type in MATH_OPERATORS
        ):
            return NO

    elif prev.type in OPENING_BRACKETS:
+4 −0
Changes for tests/expression.py: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -63,6 +63,8 @@
[((i ** 2) + j) for i in (1, 2, 3) for j in (1, 2, 3)]
{i: 0 for i in (1, 2, 3)}
{i: j for i, j in ((1, 'a'), (2, 'b'), (3, 'c'))}
{a: b * 2 for a, b in dictionary.items()}
{a: b * -2 for a, b in dictionary.items()}
{k: v for k, v in this_is_a_very_long_variable_which_will_cause_a_trailing_comma_which_breaks_the_comprehension}
Python3 > Python2 > COBOL
Life is Life
@@ -214,6 +216,8 @@ async def f():
[((i ** 2) + j) for i in (1, 2, 3) for j in (1, 2, 3)]
{i: 0 for i in (1, 2, 3)}
{i: j for i, j in ((1, 'a'), (2, 'b'), (3, 'c'))}
{a: b * 2 for a, b in dictionary.items()}
{a: b * -2 for a, b in dictionary.items()}
{
    k: v
    for k, v in this_is_a_very_long_variable_which_will_cause_a_trailing_comma_which_breaks_the_comprehension