Skip to content

Commit 602599e

Browse files
authored
Merge branch 'main' into psfgh-3545
2 parents d2cad58 + 53a2190 commit 602599e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+209
-167
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ repos:
3939
exclude: ^src/blib2to3/
4040

4141
- repo: https://github.com/pre-commit/mirrors-mypy
42-
rev: v1.11.2
42+
rev: v1.12.0
4343
hooks:
4444
- id: mypy
4545
exclude: ^(docs/conf.py|scripts/generate_schema.py)$

CHANGES.md

+53
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,58 @@
11
# Change Log
22

3+
## Unreleased
4+
5+
### Highlights
6+
7+
<!-- Include any especially major or disruptive changes here -->
8+
9+
### Stable style
10+
11+
<!-- Changes that affect Black's stable style -->
12+
13+
- Fix formatting cells in IPython notebooks with magic methods and starting or trailing
14+
empty lines (#4484)
15+
16+
### Preview style
17+
18+
<!-- Changes that affect Black's preview style -->
19+
20+
### Configuration
21+
22+
<!-- Changes to how Black can be configured -->
23+
24+
### Packaging
25+
26+
<!-- Changes to how Black is packaged, such as dependency requirements -->
27+
28+
- Store license identifier inside the `License-Expression` metadata field, see
29+
[PEP 639](https://peps.python.org/pep-0639/). (#4479)
30+
31+
### Parser
32+
33+
<!-- Changes to the parser or to version autodetection -->
34+
35+
### Performance
36+
37+
<!-- Changes that improve Black's performance. -->
38+
39+
### Output
40+
41+
<!-- Changes to Black's terminal output and error messages -->
42+
43+
### _Blackd_
44+
45+
<!-- Changes to blackd -->
46+
47+
### Integrations
48+
49+
<!-- For example, Docker, GitHub Actions, pre-commit, editors -->
50+
51+
### Documentation
52+
53+
<!-- Major changes to documentation and policies. Small docs changes
54+
don't need a changelog entry. -->
55+
356
## 24.10.0
457

558
### Highlights

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Try it out now using the [Black Playground](https://black.vercel.app). Watch the
3838

3939
### Installation
4040

41-
_Black_ can be installed by running `pip install black`. It requires Python 3.8+ to run.
41+
_Black_ can be installed by running `pip install black`. It requires Python 3.9+ to run.
4242
If you want to format Jupyter Notebooks, install with `pip install "black[jupyter]"`.
4343

4444
If you can't wait for the latest _hotness_ and want to install from GitHub, use:

autoload/black.vim

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def _initialize_black_env(upgrade=False):
7676

7777
pyver = sys.version_info[:3]
7878
if pyver < (3, 8):
79-
print("Sorry, Black requires Python 3.8+ to run.")
79+
print("Sorry, Black requires Python 3.9+ to run.")
8080
return False
8181

8282
from pathlib import Path

docs/faq.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,17 @@ See [Using _Black_ with other tools](labels/why-pycodestyle-warnings).
8484

8585
## Which Python versions does Black support?
8686

87-
Currently the runtime requires Python 3.8-3.11. Formatting is supported for files
88-
containing syntax from Python 3.3 to 3.11. We promise to support at least all Python
89-
versions that have not reached their end of life. This is the case for both running
90-
_Black_ and formatting code.
87+
_Black_ generally supports all Python versions supported by CPython (see
88+
[the Python devguide](https://devguide.python.org/versions/) for current information).
89+
We promise to support at least all Python versions that have not reached their end of
90+
life. This is the case for both running _Black_ and formatting code.
9191

9292
Support for formatting Python 2 code was removed in version 22.0. While we've made no
9393
plans to stop supporting older Python 3 minor versions immediately, their support might
9494
also be removed some time in the future without a deprecation period.
9595

96-
Runtime support for 3.7 was removed in version 23.7.0.
96+
Runtime support for 3.6 was removed in version 22.10.0, for 3.7 in version 23.7.0, and
97+
for 3.8 in version 24.10.0.
9798

9899
## Why does my linter or typechecker complain after I format my code?
99100

docs/getting_started.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Also, you can try out _Black_ online for minimal fuss on the
1616

1717
## Installation
1818

19-
_Black_ can be installed by running `pip install black`. It requires Python 3.8+ to run.
19+
_Black_ can be installed by running `pip install black`. It requires Python 3.9+ to run.
2020
If you want to format Jupyter Notebooks, install with `pip install "black[jupyter]"`.
2121

2222
If you use pipx, you can install Black with `pipx install black`.

docs/integrations/editors.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ Configuration:
236236

237237
#### Installation
238238

239-
This plugin **requires Vim 7.0+ built with Python 3.8+ support**. It needs Python 3.8 to
239+
This plugin **requires Vim 7.0+ built with Python 3.9+ support**. It needs Python 3.9 to
240240
be able to run _Black_ inside the Vim process which is much faster than calling an
241241
external command.
242242

docs/integrations/github_actions.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,14 @@ If you want to match versions covered by Black's
7474
version: "~= 22.0"
7575
```
7676

77-
If you want to read the version from `pyproject.toml`, set `use_pyproject` to `true`:
77+
If you want to read the version from `pyproject.toml`, set `use_pyproject` to `true`.
78+
Note that this requires Python >= 3.11, so using the setup-python action may be
79+
required, for example:
7880

7981
```yaml
82+
- uses: actions/setup-python@v5
83+
with:
84+
python-version: "3.13"
8085
- uses: psf/black@stable
8186
with:
8287
options: "--check --verbose"

docs/usage_and_configuration/the_basics.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,17 @@ See also [the style documentation](labels/line-length).
7070

7171
Python versions that should be supported by Black's output. You can run `black --help`
7272
and look for the `--target-version` option to see the full list of supported versions.
73-
You should include all versions that your code supports. If you support Python 3.8
74-
through 3.11, you should write:
73+
You should include all versions that your code supports. If you support Python 3.11
74+
through 3.13, you should write:
7575

7676
```console
77-
$ black -t py38 -t py39 -t py310 -t py311
77+
$ black -t py311 -t py312 -t py313
7878
```
7979

8080
In a [configuration file](#configuration-via-a-file), you can write:
8181

8282
```toml
83-
target-version = ["py38", "py39", "py310", "py311"]
83+
target-version = ["py311", "py312", "py313"]
8484
```
8585

8686
By default, Black will infer target versions from the project metadata in

gallery/gallery.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
import venv
88
import zipfile
99
from argparse import ArgumentParser, Namespace
10+
from collections.abc import Generator
1011
from concurrent.futures import ThreadPoolExecutor
1112
from functools import lru_cache, partial
1213
from pathlib import Path
13-
from typing import Generator, List, NamedTuple, Optional, Tuple, Union, cast
14+
from typing import NamedTuple, Optional, Union, cast
1415
from urllib.request import urlopen, urlretrieve
1516

1617
PYPI_INSTANCE = "https://pypi.org/pypi"
@@ -54,7 +55,7 @@ def get_pypi_download_url(package: str, version: Optional[str]) -> str:
5455
return cast(str, source["url"])
5556

5657

57-
def get_top_packages() -> List[str]:
58+
def get_top_packages() -> list[str]:
5859
with urlopen(PYPI_TOP_PACKAGES) as page:
5960
result = json.load(page)
6061

@@ -150,7 +151,7 @@ def git_switch_branch(
150151
subprocess.run(args, cwd=repo)
151152

152153

153-
def init_repos(options: Namespace) -> Tuple[Path, ...]:
154+
def init_repos(options: Namespace) -> tuple[Path, ...]:
154155
options.output.mkdir(exist_ok=True)
155156

156157
if options.top_packages:
@@ -206,7 +207,7 @@ def format_repo_with_version(
206207
git_switch_branch(black_version.version, repo=black_repo)
207208
git_switch_branch(current_branch, repo=repo, new=True, from_branch=from_branch)
208209

209-
format_cmd: List[Union[Path, str]] = [
210+
format_cmd: list[Union[Path, str]] = [
210211
black_runner(black_version.version, black_repo),
211212
(black_repo / "black.py").resolve(),
212213
".",
@@ -222,7 +223,7 @@ def format_repo_with_version(
222223
return current_branch
223224

224225

225-
def format_repos(repos: Tuple[Path, ...], options: Namespace) -> None:
226+
def format_repos(repos: tuple[Path, ...], options: Namespace) -> None:
226227
black_versions = tuple(
227228
BlackVersion(*version.split(":")) for version in options.versions
228229
)

plugin/black.vim

+4-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ endif
2121

2222
if v:version < 700 || !has('python3')
2323
func! __BLACK_MISSING()
24-
echo "The black.vim plugin requires vim7.0+ with Python 3.6 support."
24+
echo "The black.vim plugin requires vim7.0+ with Python 3.9 support."
2525
endfunc
2626
command! Black :call __BLACK_MISSING()
2727
command! BlackUpgrade :call __BLACK_MISSING()
@@ -72,12 +72,11 @@ endif
7272

7373
function BlackComplete(ArgLead, CmdLine, CursorPos)
7474
return [
75-
\ 'target_version=py27',
76-
\ 'target_version=py36',
77-
\ 'target_version=py37',
78-
\ 'target_version=py38',
7975
\ 'target_version=py39',
8076
\ 'target_version=py310',
77+
\ 'target_version=py311',
78+
\ 'target_version=py312',
79+
\ 'target_version=py313',
8180
\ ]
8281
endfunction
8382

pyproject.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ build-backend = "hatchling.build"
3333
[project]
3434
name = "black"
3535
description = "The uncompromising code formatter."
36-
license = { text = "MIT" }
36+
license = "MIT"
3737
requires-python = ">=3.9"
3838
authors = [
3939
{ name = "Łukasz Langa", email = "[email protected]" },
@@ -125,7 +125,7 @@ macos-max-compat = true
125125
enable-by-default = false
126126
dependencies = [
127127
"hatch-mypyc>=0.16.0",
128-
"mypy @ git+https://github.com/python/mypy@bc8119150e49895f7a496ae7ae7362a2828e7e9e",
128+
"mypy>=1.12",
129129
"click>=8.1.7",
130130
]
131131
require-runtime-dependencies = true
@@ -192,7 +192,7 @@ build-frontend = { name = "build", args = ["--no-isolation"] }
192192
# Note we don't have a good test for this sed horror, so if you futz with it
193193
# make sure to test manually
194194
before-build = [
195-
"python -m pip install 'hatchling==1.20.0' hatch-vcs hatch-fancy-pypi-readme 'hatch-mypyc>=0.16.0' 'mypy @ git+https://github.com/python/mypy@bc8119150e49895f7a496ae7ae7362a2828e7e9e' 'click>=8.1.7'",
195+
"python -m pip install 'hatchling==1.20.0' hatch-vcs hatch-fancy-pypi-readme 'hatch-mypyc>=0.16.0' 'mypy>=1.12' 'click>=8.1.7'",
196196
"""sed -i '' -e "600,700s/'10_16'/os.environ['MACOSX_DEPLOYMENT_TARGET'].replace('.', '_')/" $(python -c 'import hatchling.builders.wheel as h; print(h.__file__)') """,
197197
]
198198

scripts/make_width_table.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
"""
1818

1919
import sys
20+
from collections.abc import Iterable
2021
from os.path import basename, dirname, join
21-
from typing import Iterable, Tuple
2222

2323
import wcwidth # type: ignore[import-not-found]
2424

2525

26-
def make_width_table() -> Iterable[Tuple[int, int, int]]:
26+
def make_width_table() -> Iterable[tuple[int, int, int]]:
2727
start_codepoint = -1
2828
end_codepoint = -1
2929
range_width = -2
@@ -53,9 +53,9 @@ def main() -> None:
5353
f.write(f"""# Generated by {basename(__file__)}
5454
# wcwidth {wcwidth.__version__}
5555
# Unicode {wcwidth.list_versions()[-1]}
56-
from typing import Final, List, Tuple
56+
from typing import Final
5757
58-
WIDTH_TABLE: Final[List[Tuple[int, int, int]]] = [
58+
WIDTH_TABLE: Final[list[tuple[int, int, int]]] = [
5959
""")
6060
for triple in make_width_table():
6161
f.write(f" {triple!r},\n")

src/black/__init__.py

+9-11
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,22 @@
55
import sys
66
import tokenize
77
import traceback
8-
from contextlib import contextmanager
9-
from dataclasses import replace
10-
from datetime import datetime, timezone
11-
from enum import Enum
12-
from json.decoder import JSONDecodeError
13-
from pathlib import Path
14-
from typing import (
15-
Any,
8+
from collections.abc import (
169
Collection,
1710
Generator,
1811
Iterator,
1912
MutableMapping,
20-
Optional,
21-
Pattern,
2213
Sequence,
2314
Sized,
24-
Union,
2515
)
16+
from contextlib import contextmanager
17+
from dataclasses import replace
18+
from datetime import datetime, timezone
19+
from enum import Enum
20+
from json.decoder import JSONDecodeError
21+
from pathlib import Path
22+
from re import Pattern
23+
from typing import Any, Optional, Union
2624

2725
import click
2826
from click.core import ParameterSource

src/black/brackets.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""Builds on top of nodes.py to track brackets."""
22

3+
from collections.abc import Iterable, Sequence
34
from dataclasses import dataclass, field
4-
from typing import Final, Iterable, Optional, Sequence, Union
5+
from typing import Final, Optional, Union
56

67
from black.nodes import (
78
BRACKET,

src/black/cache.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
import pickle
66
import sys
77
import tempfile
8+
from collections.abc import Iterable
89
from dataclasses import dataclass, field
910
from pathlib import Path
10-
from typing import Iterable, NamedTuple
11+
from typing import NamedTuple
1112

1213
from platformdirs import user_cache_dir
1314

src/black/comments.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import re
2+
from collections.abc import Collection, Iterator
23
from dataclasses import dataclass
34
from functools import lru_cache
4-
from typing import Collection, Final, Iterator, Optional, Union
5+
from typing import Final, Optional, Union
56

67
from black.mode import Mode, Preview
78
from black.nodes import (

src/black/concurrency.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
import signal
1111
import sys
1212
import traceback
13+
from collections.abc import Iterable
1314
from concurrent.futures import Executor, ProcessPoolExecutor, ThreadPoolExecutor
1415
from multiprocessing import Manager
1516
from pathlib import Path
16-
from typing import Any, Iterable, Optional
17+
from typing import Any, Optional
1718

1819
from mypy_extensions import mypyc_attr
1920

src/black/debug.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from collections.abc import Iterator
12
from dataclasses import dataclass, field
2-
from typing import Any, Iterator, TypeVar, Union
3+
from typing import Any, TypeVar, Union
34

45
from black.nodes import Visitor
56
from black.output import out

0 commit comments

Comments
 (0)