From 5370714c963fa59d84356e2841882e42ab16641e Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C5=81ukasz=20Langa?= Date: Thu, 15 Mar 2018 14:54:37 -0700 Subject: [PATCH] Fix spurious space after unary expression This happened when the operand was a complex expression. Fixes #15 --- README.md | 6 ++++++ black.py | 3 +++ tests/expression.py | 2 ++ 3 files changed, 11 insertions(+) diff --git a/README.md b/README.md index 63fb4b2..c0870a8 100644 --- a/README.md +++ b/README.md @@ -257,6 +257,12 @@ You can still try but prepare to be disappointed. * fixed spurious space in parenthesized set expressions (#7) +* fixed spurious space after opening parentheses and in default + arguments (#14, #17) + +* fixed spurious space after unary operators when the operand was + a complex expression (#15) + ### 18.3a0 diff --git a/black.py b/black.py index 75fbdca..d48fddb 100644 --- a/black.py +++ b/black.py @@ -815,6 +815,9 @@ 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: + return NO + elif prev.type in OPENING_BRACKETS: return NO diff --git a/tests/expression.py b/tests/expression.py index 1d9f0ab..6870749 100644 --- a/tests/expression.py +++ b/tests/expression.py @@ -31,6 +31,7 @@ not great -1 ~int and not v1 ^ 123 + v2 | True (~int) and (not ((v1 ^ (123 + v2)) | True)) +flags & ~ select.EPOLLIN and waiters.write_task is not None lambda arg: None lambda a=True: a lambda a, b, c=True: a @@ -155,6 +156,7 @@ not great -1 ~int and not v1 ^ 123 + v2 | True (~int) and (not ((v1 ^ (123 + v2)) | True)) +flags & ~select.EPOLLIN and waiters.write_task is not None lambda arg: None lambda a=True: a lambda a, b, c=True: a -- 2.39.5