From d80ce36dfade8ad9a8555a4e0bc7fe96169217e2 Mon Sep 17 00:00:00 2001 From: felix-hilden Date: Fri, 24 Jun 2022 10:33:11 +0300 Subject: [PATCH 1/5] Update preview docs for #2926, #2990, #2991, #3035 --- docs/the_black_code_style/future_style.md | 26 +++++++++++++++++------ 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/docs/the_black_code_style/future_style.md b/docs/the_black_code_style/future_style.md index 8d159e9b0a2..ef8323801b8 100644 --- a/docs/the_black_code_style/future_style.md +++ b/docs/the_black_code_style/future_style.md @@ -52,25 +52,37 @@ tracked in [this issue](https://github.com/psf/black/issues/2188). ### Removing trailing newlines after code block open -_Black_ will remove trailing newlines after code block openings. That means that the -following code: +_Black_ will remove trailing newlines after code block openings. For example: ```python def my_func(): print("The line above me will be deleted!") - - print("But the line above me won't!") ``` -Will be changed to: +will be changed to: ```python def my_func(): print("The line above me will be deleted!") - - print("But the line above me won't!") ``` This new feature will be applied to **all code blocks**: `def`, `class`, `if`, `for`, `while`, `with`, `case` and `match`. + +### Improved parentheses management + +_Black_ will format parentheses around return annotations, await expressions and with +statements similarly to other sets of parentheses. For example: + +```python +with ((open("bla.txt")) as f, open("x")): + pass +``` + +will be changed to: + +```python +with open("bla.txt") as f, open("x"): + pass +``` From 1aaa47c41fbbfcb8b5fc3fad3f75d1552f56f276 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Hild=C3=A9n?= Date: Sat, 25 Jun 2022 01:43:18 +0300 Subject: [PATCH 2/5] Update docs/the_black_code_style/future_style.md Co-authored-by: Jelle Zijlstra --- docs/the_black_code_style/future_style.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/the_black_code_style/future_style.md b/docs/the_black_code_style/future_style.md index ef8323801b8..a08c11bddec 100644 --- a/docs/the_black_code_style/future_style.md +++ b/docs/the_black_code_style/future_style.md @@ -72,7 +72,7 @@ This new feature will be applied to **all code blocks**: `def`, `class`, `if`, ` ### Improved parentheses management -_Black_ will format parentheses around return annotations, await expressions and with +_Black_ will format parentheses around return annotations, `await` expressions and `with` statements similarly to other sets of parentheses. For example: ```python From f86510f3ad8883beba6f6e73bd952d4db05a98c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Hild=C3=A9n?= Date: Sat, 25 Jun 2022 09:59:24 +0300 Subject: [PATCH 3/5] fix lint --- docs/the_black_code_style/future_style.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/the_black_code_style/future_style.md b/docs/the_black_code_style/future_style.md index a08c11bddec..aa00e875e19 100644 --- a/docs/the_black_code_style/future_style.md +++ b/docs/the_black_code_style/future_style.md @@ -72,8 +72,8 @@ This new feature will be applied to **all code blocks**: `def`, `class`, `if`, ` ### Improved parentheses management -_Black_ will format parentheses around return annotations, `await` expressions and `with` -statements similarly to other sets of parentheses. For example: +_Black_ will format parentheses around return annotations, `await` expressions and +`with` statements similarly to other sets of parentheses. For example: ```python with ((open("bla.txt")) as f, open("x")): From aa977ce43821d388e82cbb02ea2e1a56d95ba688 Mon Sep 17 00:00:00 2001 From: felix-hilden Date: Sun, 26 Jun 2022 17:10:50 +0300 Subject: [PATCH 4/5] Address comments --- docs/the_black_code_style/future_style.md | 41 +++++++++++++++++++---- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/docs/the_black_code_style/future_style.md b/docs/the_black_code_style/future_style.md index aa00e875e19..845379170b1 100644 --- a/docs/the_black_code_style/future_style.md +++ b/docs/the_black_code_style/future_style.md @@ -50,9 +50,10 @@ limit. Line continuation backslashes are converted into parenthesized strings. Unnecessary parentheses are stripped. The stability and status of this feature is tracked in [this issue](https://github.com/psf/black/issues/2188). -### Removing trailing newlines after code block open +### Removing newlines in the beginning of code blocks -_Black_ will remove trailing newlines after code block openings. For example: +_Black_ will remove newlines in the beginning of new code blocks, i.e. when the +indentation level is increased. For example: ```python def my_func(): @@ -72,17 +73,45 @@ This new feature will be applied to **all code blocks**: `def`, `class`, `if`, ` ### Improved parentheses management -_Black_ will format parentheses around return annotations, `await` expressions and -`with` statements similarly to other sets of parentheses. For example: +_Black_ will format parentheses around return annotations similarly to other sets of +parentheses. For example: + +```python +def foo() -> (int): + ... +``` + +will be changed to: + +```python +def foo() -> int: + ... +``` + +```python +def foo() -> looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong: + ... +``` + +will be changed to: + +```python +def foo() -> ( + looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong +): + ... +``` + +Extra parentheses in `await` expressions and `with` statements are removed. ```python with ((open("bla.txt")) as f, open("x")): - pass + ... ``` will be changed to: ```python with open("bla.txt") as f, open("x"): - pass + ... ``` From f36862cab3d033ab3763f4b93ce4df9d3933b39a Mon Sep 17 00:00:00 2001 From: Richard Si <63936253+ichard26@users.noreply.github.com> Date: Mon, 27 Jun 2022 16:11:55 -0400 Subject: [PATCH 5/5] Improve flow (brought to you by sleep) --- docs/the_black_code_style/future_style.md | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/docs/the_black_code_style/future_style.md b/docs/the_black_code_style/future_style.md index 845379170b1..fab4bca120e 100644 --- a/docs/the_black_code_style/future_style.md +++ b/docs/the_black_code_style/future_style.md @@ -79,6 +79,9 @@ parentheses. For example: ```python def foo() -> (int): ... + +def foo() -> looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong: + ... ``` will be changed to: @@ -86,27 +89,23 @@ will be changed to: ```python def foo() -> int: ... -``` - -```python -def foo() -> looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong: - ... -``` -will be changed to: -```python def foo() -> ( looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong ): ... ``` -Extra parentheses in `await` expressions and `with` statements are removed. +And, extra parentheses in `await` expressions and `with` statements are removed. For +example: ```python with ((open("bla.txt")) as f, open("x")): ... + +async def main(): + await (asyncio.sleep(1)) ``` will be changed to: @@ -114,4 +113,8 @@ will be changed to: ```python with open("bla.txt") as f, open("x"): ... + + +async def main(): + await asyncio.sleep(1) ```