Skip to content

Commit eb5d175

Browse files
felix-hildenJelleZijlstraichard26
authored
Update preview style docs to include recent changes (#3136)
Covers GH-2926, GH-2990, GH-2991, and GH-3035. Co-authored-by: Jelle Zijlstra <[email protected]> Co-authored-by: Richard Si <[email protected]>
1 parent d848209 commit eb5d175

File tree

1 file changed

+52
-8
lines changed

1 file changed

+52
-8
lines changed

docs/the_black_code_style/future_style.md

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,27 +50,71 @@ limit. Line continuation backslashes are converted into parenthesized strings.
5050
Unnecessary parentheses are stripped. The stability and status of this feature is
5151
tracked in [this issue](https://github.com/psf/black/issues/2188).
5252

53-
### Removing trailing newlines after code block open
53+
### Removing newlines in the beginning of code blocks
5454

55-
_Black_ will remove trailing newlines after code block openings. That means that the
56-
following code:
55+
_Black_ will remove newlines in the beginning of new code blocks, i.e. when the
56+
indentation level is increased. For example:
5757

5858
```python
5959
def my_func():
6060

6161
print("The line above me will be deleted!")
62-
63-
print("But the line above me won't!")
6462
```
6563

66-
Will be changed to:
64+
will be changed to:
6765

6866
```python
6967
def my_func():
7068
print("The line above me will be deleted!")
71-
72-
print("But the line above me won't!")
7369
```
7470

7571
This new feature will be applied to **all code blocks**: `def`, `class`, `if`, `for`,
7672
`while`, `with`, `case` and `match`.
73+
74+
### Improved parentheses management
75+
76+
_Black_ will format parentheses around return annotations similarly to other sets of
77+
parentheses. For example:
78+
79+
```python
80+
def foo() -> (int):
81+
...
82+
83+
def foo() -> looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong:
84+
...
85+
```
86+
87+
will be changed to:
88+
89+
```python
90+
def foo() -> int:
91+
...
92+
93+
94+
def foo() -> (
95+
looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong
96+
):
97+
...
98+
```
99+
100+
And, extra parentheses in `await` expressions and `with` statements are removed. For
101+
example:
102+
103+
```python
104+
with ((open("bla.txt")) as f, open("x")):
105+
...
106+
107+
async def main():
108+
await (asyncio.sleep(1))
109+
```
110+
111+
will be changed to:
112+
113+
```python
114+
with open("bla.txt") as f, open("x"):
115+
...
116+
117+
118+
async def main():
119+
await asyncio.sleep(1)
120+
```

0 commit comments

Comments
 (0)