]> 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 incorrect space before colon in if/while stmts (#1655)
authorRichard Si <63936253+ichard26@users.noreply.github.com>
Mon, 31 Aug 2020 21:20:05 +0000 (17:20 -0400)
committerGitHub <noreply@github.com>
Mon, 31 Aug 2020 21:20:05 +0000 (14:20 -0700)
* Fix incorrect space before colon in if/while stmts

Previously Black would format this code

```
if (foo := True):
print(foo)
```

as

```
if (foo := True) :
print(foo)
```

adding an incorrect space after the RPAR. Buggy code in the
normalize_invisible_parens function caused the colon to be wrapped in
invisible parentheses. The LPAR of that pair was then prefixed with a
single space at the request of the whitespace function.

This commit fixes the accidental skipping of a pre-condition check
which must return True before parenthesis normalization of a specific
child Leaf or Node can happen. The pre-condition check being skipped
was why the colon was wrapped in invisible parentheses.

* Add an entry in CHANGES.md

CHANGES.md
docs/change_log.md
src/black/__init__.py
tests/data/pep_572.py

index 1c53604d4d5bd0ce234f60e13ddfb6b5fbbdb4ab..7e356f1f29c4283afeb98ce58f5543978e4aab17 100644 (file)
@@ -7,6 +7,9 @@
 - `Black` now respects `--skip-string-normalization` when normalizing multiline
   docstring quotes (#1637)
 
+- `Black` no longer adds an incorrect space after a parenthesized assignment expression
+  in if/while statements (#1655)
+
 - fixed a crash when PWD=/ on POSIX (#1631)
 
 ### 20.8b1
index b73371666596edc39dd480c54f5547e7d36c06b7..cc5015f873c26d3417b4c99afc0909808caf0969 100644 (file)
@@ -9,6 +9,11 @@
 - `Black` now respects `--skip-string-normalization` when normalizing multiline
   docstring quotes (#1637)
 
+- `Black` no longer adds an incorrect space after a parenthesized assignment expression
+  in if/while statements (#1655)
+
+- fixed a crash when PWD=/ on POSIX (#1631)
+
 ### 20.8b1
 
 #### _Packaging_
index 048e771ce961304eefe6b4b882beb8b02830e0da..64a18655905c9a03c92e89653e3aed93b89535a3 100644 (file)
@@ -5190,9 +5190,9 @@ def normalize_invisible_parens(node: Node, parens_after: Set[str]) -> None:
 
         if check_lpar:
             if is_walrus_assignment(child):
-                continue
+                pass
 
-            if child.type == syms.atom:
+            elif child.type == syms.atom:
                 if maybe_make_parens_invisible_in_atom(child, parent=node):
                     wrap_in_parentheses(node, child, visible=False)
             elif is_one_tuple(child):
index 9e429f913cefb132f5dfd3ffb47728fea6e63747..637b3bb38c6b218864ebff5877b0801e2f0bfb62 100644 (file)
@@ -2,6 +2,8 @@
 (a := a)
 if (match := pattern.search(data)) is None:
     pass
+if (match := pattern.search(data)):
+    pass
 [y := f(x), y ** 2, y ** 3]
 filtered_data = [y for x in data if (y := f(x)) is None]
 (y := f(x))
@@ -41,3 +43,5 @@ foo(c=(b := 2), a=1)
 
 while x := f(x):
     pass
+while (x := f(x)):
+    pass