Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect space before colon in if/while stmts #1655

Merged
merged 2 commits into from Aug 31, 2020

Conversation

ichard26
Copy link
Collaborator

@ichard26 ichard26 commented Aug 29, 2020

Fixes #1174
Fixes #1588

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.

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.
@ichard26

This comment has been minimized.

@cooperlees cooperlees merged commit 1d2d726 into psf:master Aug 31, 2020
@ichard26 ichard26 deleted the fix_incorrect_space branch August 31, 2020 22:36
@JonZeolla
Copy link

Any chance this can be included in the upcoming release?

@ichard26
Copy link
Collaborator Author

ichard26 commented Sep 2, 2020

I'm confused, we release what's been merged into master, so unless a commit reintroduces the bug (which will get detected as I added a test case), the next release will include this fix.

@JonZeolla
Copy link

Great to hear. I mistook the beta tag and the use of "stable" on read the docs for an expectation of a more immediate non-beta release, but in reviewing the documentation and prior releases, that doesn't appear to be likely. I will keep an eye on future releases

noxan pushed a commit to noxan/black that referenced this pull request Jun 6, 2021
* 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
HectorMenezes added a commit to HectorMenezes/pre-commit.com that referenced this pull request Jan 6, 2022
Black used to have a problem with [assignment expression](psf/black#1655). Now the docs provide a black version that won't break.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Internal Error ") :" Incorrect Space Added after Assignment Expression in If Statement
4 participants