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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update preview style docs to include recent changes #3136

Merged
merged 5 commits into from Jun 27, 2022
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
57 changes: 49 additions & 8 deletions docs/the_black_code_style/future_style.md
Expand Up @@ -50,27 +50,68 @@ 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. That means that the
following code:
_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():

print("The line above me will be deleted!")

print("But the line above me won't!")
felix-hilden marked this conversation as resolved.
Show resolved Hide resolved
```

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
felix-hilden marked this conversation as resolved.
Show resolved Hide resolved

_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")):
...
```

will be changed to:

```python
with open("bla.txt") as f, open("x"):
...
```