The uncompromising Python code formatter
git archive
is skipped (#4313)if
guards in case
blocks are now wrapped in parentheses when the line is too long.
(#4269)use_pyproject
to the GitHub Action psf/black
. This will read the
Black version from pyproject.toml
. (#4294)This release is a milestone: it fixes Black's first CVE security vulnerability. If you run Black on untrusted input, or if you habitually put thousands of leading tab characters in your docstrings, you are strongly encouraged to upgrade immediately to fix CVE-2024-21503.
This release also fixes a bug in Black's AST safety check that allowed Black to make incorrect changes to certain f-strings that are valid in Python 3.12 and higher.
--check
is used with --quiet
(#4236)hug_parens_with_braces_and_square_brackets
feature to the unstable style
due to an outstanding crash and proposed formatting tweaks (#4198)case
statement if
guards (#4214).pyproject.toml
that is missing a tool.black
section when
discovering project root and configuration. Since Black continues to use version
control as an indicator of project root, this is expected to primarily change behavior
for users in a monorepo setup (desirably). If you wish to preserve previous behavior,
simply add an empty [tool.black]
to the previously discovered pyproject.toml
(#4204)SyntaxWarning
s or DeprecationWarning
s produced by the ast
module when performing equivalence checks (#4189)Bugfix release to fix a bug that made Black unusable on certain file systems with strict limits on path length.
This release introduces the new 2024 stable style (#4106), stabilizing the following changes:
if
-else
expressions (#2278)...
are formatted more
compactly (#3796)with
statement
(#3489)--skip-magic-trailing-comma
or -C
, trailing commas are stripped from
subscript expressions with more than 1 element (#3209)# fmt: skip
with other comments (#3959)There are already a few improvements in the --preview
style, which are slated for the
2025 stable style. Try them out and
share your feedback. In the past, the preview
style has included some features that we were not able to stabilize. This year, we're
adding a separate --unstable
style for features with known problems. Now, the
--preview
style only includes features that we actually expect to make it into next
year's stable style.
Several bug fixes were made in features that are moved to the stable style in this release:
--unstable
style, covering preview features that have known problems that would
block them from going into the stable style. Also add the --enable-unstable-feature
flag; for example, use
--enable-unstable-feature hug_parens_with_braces_and_square_brackets
to apply this
preview feature throughout 2024, even if a later Black release downgrades the feature
to unstable (#4096)# fmt: skip
comments (#4146)pyproject.toml
contains an invalid key (#4165)--experimental-string-processing
flag. This feature can
currently be enabled with --preview --enable-unstable-feature string_processing
.
(#4096)Thank you to everyone who provided feedback to help make Black's 2024 style even better. Thank you also to everyone who contributed code to Black.
Fixed a bug that included dependencies from the d extra by default (#4108)
It's almost 2024, which means it's time for a new edition of Black's stable style! Together with this release, we'll put out an alpha release 24.1a1 showcasing the draft 2024 stable style, which we'll finalize in the January release. Please try it out and share your feedback.
This release (23.12.0) will still produce the 2023 style. Most but not all of the
changes in --preview
mode will be in the 2024 stable style.
# fmt: off
automatically dedents when used with the --line-ranges
option, even when it is not within the specified line range. (#4084)--line-length
(#4086)--line-ranges
now skips Black's internal stability check in --safe
mode. This
avoids a crash on rare inputs that have many unformatted same-content lines. (#4034)This is a preview of the 2024 stable style, showing the formatting that Black will use in 2024. Please test it out and share your feedback.
This applies the following changes:
...
are formatted more
compactly (#3796)with
statement
(#3489)--skip-magic-trailing-comma
or -C
, trailing commas are stripped from
subscript expressions with more than 1 element (#3209)# fmt: skip
with other comments (#3959)The following two changes may be included, but have outstanding issues that will need to be resolved:
if
-else
expressions (#2278)