Skip to content

Commit

Permalink
Merge branch 'main' into east-asian-width
Browse files Browse the repository at this point in the history
  • Loading branch information
JelleZijlstra committed Feb 1, 2023
2 parents 0cdb8e4 + b0d1fba commit ff88d9c
Show file tree
Hide file tree
Showing 47 changed files with 505 additions and 320 deletions.
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Expand Up @@ -24,7 +24,7 @@ repos:
additional_dependencies: *version_check_dependencies

- repo: https://github.com/pycqa/isort
rev: 5.10.1
rev: 5.12.0
hooks:
- id: isort

Expand All @@ -48,6 +48,7 @@ repos:
- tomli >= 0.2.6, < 2.0.0
- types-typed-ast >= 1.4.1
- click >= 8.1.0
- packaging >= 22.0
- platformdirs >= 2.1.0
- pytest
- hypothesis
Expand Down
124 changes: 104 additions & 20 deletions CHANGES.md
Expand Up @@ -10,15 +10,108 @@

<!-- Changes that affect Black's stable style -->

### Preview style

<!-- Changes that affect Black's preview style -->

- Let string splitters respect [East Asian Width](https://www.unicode.org/reports/tr11/)
(#3445)
- Now long string literals can be split after East Asian commas and periods (`` U+3001
IDEOGRAPHIC COMMA, `` U+3002 IDEOGRAPHIC FULL STOP, & `` U+FF0C FULLWIDTH COMMA)
besides before spaces (#3445)

### Configuration

<!-- Changes to how Black can be configured -->

### Packaging

<!-- Changes to how Black is packaged, such as dependency requirements -->

### Parser

<!-- Changes to the parser or to version autodetection -->

### Performance

<!-- Changes that improve Black's performance. -->

### Output

<!-- Changes to Black's terminal output and error messages -->

### _Blackd_

<!-- Changes to blackd -->

### Integrations

<!-- For example, Docker, GitHub Actions, pre-commit, editors -->

### Documentation

<!-- Major changes to documentation and policies. Small docs changes
don't need a changelog entry. -->

## 23.1.0

### Highlights

This is the first release of 2023, and following our
[stability policy](https://black.readthedocs.io/en/stable/the_black_code_style/index.html#stability-policy),
it comes with a number of improvements to our stable style, including improvements to
empty line handling, removal of redundant parentheses in several contexts, and output
that highlights implicitly concatenated strings better.

There are also many changes to the preview style; try out `black --preview` and give us
feedback to help us set the stable style for next year.

In addition to style changes, Black now automatically infers the supported Python
versions from your `pyproject.toml` file, removing the need to set Black's target
versions separately.

### Stable style

<!-- Changes that affect Black's stable style -->

- Introduce the 2023 stable style, which incorporates most aspects of last year's
preview style (#3418). Specific changes:
- Enforce empty lines before classes and functions with sticky leading comments
(#3302) (22.12.0)
- Reformat empty and whitespace-only files as either an empty file (if no newline is
present) or as a single newline character (if a newline is present) (#3348)
(22.12.0)
- Implicitly concatenated strings used as function args are now wrapped inside
parentheses (#3307) (22.12.0)
- Correctly handle trailing commas that are inside a line's leading non-nested parens
(#3370) (22.12.0)
- `--skip-string-normalization` / `-S` now prevents docstring prefixes from being
normalized as expected (#3168) (since 22.8.0)
- When using `--skip-magic-trailing-comma` or `-C`, trailing commas are stripped from
subscript expressions with more than 1 element (#3209) (22.8.0)
- Implicitly concatenated strings inside a list, set, or tuple are now wrapped inside
parentheses (#3162) (22.8.0)
- Fix a string merging/split issue when a comment is present in the middle of
implicitly concatenated strings on its own line (#3227) (22.8.0)
- Docstring quotes are no longer moved if it would violate the line length limit
(#3044, #3430) (22.6.0)
- Parentheses around return annotations are now managed (#2990) (22.6.0)
- Remove unnecessary parentheses around awaited objects (#2991) (22.6.0)
- Remove unnecessary parentheses in `with` statements (#2926) (22.6.0)
- Remove trailing newlines after code block open (#3035) (22.6.0)
- Code cell separators `#%%` are now standardised to `# %%` (#2919) (22.3.0)
- Remove unnecessary parentheses from `except` statements (#2939) (22.3.0)
- Remove unnecessary parentheses from tuple unpacking in `for` loops (#2945) (22.3.0)
- Avoid magic-trailing-comma in single-element subscripts (#2942) (22.3.0)
- Fix a crash when a colon line is marked between `# fmt: off` and `# fmt: on` (#3439)

### Preview style

<!-- Changes that affect Black's preview style -->

- Format hex code in unicode escape sequences in string literals (#2916)
- Format hex codes in unicode escape sequences in string literals (#2916)
- Add parentheses around `if`-`else` expressions (#2278)
- Improve the performance on large expressions that contain many strings (#3467)
- Improve performance on large expressions that contain many strings (#3467)
- Fix a crash in preview style with assert + parenthesized string (#3415)
- Fix crashes in preview style with walrus operators used in function return annotations
and except clauses (#3423)
Expand All @@ -42,33 +135,28 @@
- Fix an invalid quote escaping bug in f-string expressions where it produced invalid
code. Implicitly concatenated f-strings with different quotes can now be merged or
quote-normalized by changing the quotes used in expressions. (#3509)
- Let string splitters respect [East Asian Width](https://www.unicode.org/reports/tr11/)
(#3445)
- Now long string literals can be split after East Asian commas and periods (`` U+3001
IDEOGRAPHIC COMMA, `` U+3002 IDEOGRAPHIC FULL STOP, & `` U+FF0C FULLWIDTH COMMA)
besides before spaces (#3445)
- Fix crash on `await (yield)` when Black is compiled with mypyc (#3533)

### Configuration

<!-- Changes to how Black can be configured -->

- Black now tries to infer its `--target-version` from the project metadata specified in
`pyproject.toml` (#3219)

### Packaging

<!-- Changes to how Black is packaged, such as dependency requirements -->

- Upgrade mypyc from `0.971` to `0.991` so mypycified _Black_ can be built on armv7
(#3380)
- This also fixes some crashes while using compiled Black with a debug build of
CPython
- Drop specific support for the `tomli` requirement on 3.11 alpha releases, working
around a bug that would cause the requirement not to be installed on any non-final
Python releases (#3448)

### Parser

<!-- Changes to the parser or to version autodetection -->

### Performance

<!-- Changes that improve Black's performance. -->
- Black now depends on `packaging` version `22.0` or later. This is required for new
functionality that needs to parse part of the project metadata (#3219)

### Output

Expand All @@ -81,15 +169,11 @@
- Fix false symlink detection messages in verbose output due to using an incorrect
relative path to the project root (#3385)

### _Blackd_

<!-- Changes to blackd -->

### Integrations

<!-- For example, Docker, GitHub Actions, pre-commit, editors -->

- Move 3.11 CI to normal flow now all dependencies support 3.11 (#3446)
- Move 3.11 CI to normal flow now that all dependencies support 3.11 (#3446)
- Docker: Add new `latest_prerelease` tag automation to follow latest black alpha
release on docker images (#3465)

Expand Down
4 changes: 2 additions & 2 deletions docs/contributing/the_basics.md
Expand Up @@ -4,8 +4,8 @@ An overview on contributing to the _Black_ project.

## Technicalities

Development on the latest version of Python is preferred. As of this writing it's 3.9.
You can use any operating system.
Development on the latest version of Python is preferred. You can use any operating
system.

Install development dependencies inside a virtual environment of your choice, for
example:
Expand Down
2 changes: 1 addition & 1 deletion docs/integrations/source_version_control.md
Expand Up @@ -7,7 +7,7 @@ Use [pre-commit](https://pre-commit.com/). Once you
```yaml
repos:
- repo: https://github.com/psf/black
rev: 22.12.0
rev: 23.1.0
hooks:
- id: black
# It is recommended to specify the latest version of Python
Expand Down
40 changes: 39 additions & 1 deletion docs/the_black_code_style/current_style.md
Expand Up @@ -194,7 +194,45 @@ that in-function vertical whitespace should only be used sparingly.
_Black_ will allow single empty lines inside functions, and single and double empty
lines on module level left by the original editors, except when they're within
parenthesized expressions. Since such expressions are always reformatted to fit minimal
space, this whitespace is lost.
space, this whitespace is lost. The other exception is that it will remove any empty
lines immediately following a statement that introduces a new indentation level.

```python
# in:

def foo():

print("All the newlines above me should be deleted!")


if condition:

print("No newline above me!")

print("There is a newline above me, and that's OK!")


class Point:

x: int
y: int

# out:

def foo():
print("All the newlines above me should be deleted!")


if condition:
print("No newline above me!")

print("There is a newline above me, and that's OK!")


class Point:
x: int
y: int
```

It will also insert proper spacing before and after function definitions. It's one line
before and after inner functions and two lines before and after module-level functions
Expand Down
90 changes: 0 additions & 90 deletions docs/the_black_code_style/future_style.md
Expand Up @@ -62,93 +62,3 @@ plain strings. User-made splits are respected when they do not exceed the line l
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).

### Improved empty line management

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

will be changed to:

```python
def my_func():
print("The line above me will be deleted!")
```

This new feature will be applied to **all code blocks**: `def`, `class`, `if`,
`for`, `while`, `with`, `case` and `match`.

2. _Black_ will enforce empty lines before classes and functions with leading comments.
For example:

```python
some_var = 1
# Leading sticky comment
def my_func():
...
```

will be changed to:

```python
some_var = 1


# Leading sticky comment
def my_func():
...
```

### Improved parentheses management

_Black_ will format parentheses around return annotations similarly to other sets of
parentheses. For example:

```python
def foo() -> (int):
...

def foo() -> looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong:
...
```

will be changed to:

```python
def foo() -> int:
...


def foo() -> (
looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong
):
...
```

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:

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


async def main():
await asyncio.sleep(1)
```
2 changes: 1 addition & 1 deletion docs/usage_and_configuration/the_basics.md
Expand Up @@ -178,7 +178,7 @@ You can check the version of _Black_ you have installed using the `--version` fl

```console
$ black --version
black, version 22.12.0
black, version 23.1.0
```

An option to require a specific version to be running is also provided.
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Expand Up @@ -65,6 +65,7 @@ classifiers = [
dependencies = [
"click>=8.0.0",
"mypy_extensions>=0.4.3",
"packaging>=22.0",
"pathspec>=0.9.0",
"platformdirs>=2",
"tomli>=1.1.0; python_version < '3.11'",
Expand Down

0 comments on commit ff88d9c

Please sign in to comment.