pypi / black
black
What changed in black 25 to 26, from its official release notes, upgrade guides and advisories. Sources checked 2026-11-30.
11 breaking3 security10 new APIs and options6 performance18 behavior and defaults10 tooling69 fixes and other
See which of these apply to your code, ranked, in your agent:
npx @unstale/cli initblack 26101 changes
Breaking changes 10
The bundled action now rejects URL references and other non-released-version values read from tool.black.required-version, addressing a security issue.
Repeated lines outside the selected ranges are left unchanged.
Preview style parenthesizes expressions with parameter comments when they exceed the line length.
In preview style, short expressions inside brackets are not split on delimiters when preceded by a standalone comment.
Rejects non-string
force-excludevalues inpyproject.toml.Rejects non-string
includevalues inpyproject.toml.T-strings in docstring position are no longer treated as docstrings.
blackd disables browser-originated requests by default.
When enabled in the GitHub Action, parsing of Black requirements accepts only version specifiers and rejects direct references; the update is automatic with psf/black@stable.
Black now matches Git when deciding whether files are ignored: a matching pattern keeps a file ignored even if its parent directory is directly unignored.
Security 3
Black: Arbitrary file writes from unsanitized user input in cache file name
Short magics use exact-length placeholders, and unmasking aborts if it can no longer be done safely, preventing collisions from corrupting notebook cells.
blackd adds request body limits.
New APIs and options 6
Adds a command-line option to configure the cache directory.
GitHub Action runs expose the
is_formatted,change_count,same_count, andfailure_countoutputs.The environment variable disables ANSI output.
Adds
SourceASTParseErrorto distinguish source parse failures from internal safety errors and improve reporting when the lenient parser accepts input rejected byast.parse().blackd adds configurable origin allowlisting for requests.
Introduces winloop as a Windows alternative to uvloop; blackd can use it when installed to run faster on Windows.
Performance 6
Avoids quadratic runtime when splitting very long lines with many trailing bracket pairs.
Fixes superlinear runtime growth as the number of input files increases.
Improves performance on long calls and collections, soft keywords, semicolon-separated statements, deeply nested expressions, and compound statements with many clauses.
Improves performance on files with many sibling blocks.
Release binaries are smaller because debug symbols are stripped during the PyInstaller release build.
Improves performance on strings with many consecutive backslashes, multiline strings in large collections, and several string-processing operations.
Behavior and default changes 13
Preview style avoids unnecessary parentheses around unbreakable right-hand-side expressions, including in annotated assignments and subscript targets.
Validates line-range values.
Preview style enforces a blank line after a function or method with a docstring-only body when another comment or statement follows.
Unstable style splits long stringified return annotations even when the function has parameters.
The GitHub Action supports PEP 440 version specifiers for
tool.black.required-version.Improves blank-line heuristics before, within, and after groups of same-name decorated functions in
.pyistub files.Parse errors are more readable, with multi-line output and an error pointer.
blackd bounds executor submissions to improve backpressure.
The 2026 stable style always forces one blank line after import statements, except when the following line is a comment or another import.
Adds
\rstyle newlines to the newline styles that Black can normalize files from and to.Regenerates the width table and adds Khmer language support.
Expressions involving multiline strings are formatted more compactly.
Removes unnecessary parentheses from assignment left-hand sides while preserving magic trailing commas and intentional multiline formatting.
Tooling 7
Keeps parentheses around a lambda used as the iterable of a comprehension.
Reports parser failures using editor-friendly
path:line:columnlocations.Preview style normalizes uppercase
Tprefixes to lowercase.Preview style parenthesizes tuple expressions for consistency with function calls and returns.
Black adds syntactic support for lazy imports, a Python 3.15 feature.
Black adds syntactic support for unpacking in comprehensions, a Python 3.15 feature.
Formats type comments with zero or more spaces around
type:as# type: (value).
Fixes and other changes 56
Black no longer moves an encoding declaration onto the first two lines of a file.
Fixes the action crashing on dependency-group includes when
use_pyprojectis enabled.Black respects
.gitignorefiles that start with a UTF-8 byte order mark, so the first pattern matches and ignored files are not formatted.Long notebook assignment magics such as
x = !ls -laare left unchanged instead of being wrapped in parentheses that IPython can no longer run.Formatting now handles lines following a statement when that statement is joined or re-indented.
Formatting no longer crashes when an unselected statement has a
# fmt: skipcomment before a closing bracket.Files formatted or checked with selected line ranges are no longer cached as formatted, preventing later full checks from passing or skipping unformatted lines.
Black no longer adds an extra trailing blank line inside a multi-line module docstring when its last line is near the line length limit.
The unstable feature no longer removes backslash-newline sequences from raw strings and changes their value.
The unstable feature no longer adds a space after
*or**in a PEP 695 type parameter when splitting a string in its default.Preview style avoids unnecessary line splits of trailers when an earlier bracket split exceeds the line length only because of a trailing comment.
The feature no longer drops parentheses around a right-hand side containing a dictionary and leaves the line over the length limit.
Keeps parentheses around annotated-assignment targets, preserving their effect on
__annotations__.Invalid worker values are reported as usage errors instead of causing a crash.
Fixes crashes on standalone comments between tokens and preserves inline comments on brackets inside comprehensions.
When sources share no common project root, Black falls back to the default configuration with a warning instead of crashing.
Fixes multiline indentation with leading tabs and prevents form feeds or similar characters from becoming newlines.
Preserves blank lines immediately before a
# fmt: oncomment.Fixes formatting and crashes involving skipped bracketed expressions, PEP 695 declarations, headers, comments, and one-line statements.
Correctly excludes files whose paths contain
..when invoked from a subdirectory.Stops converting form feeds and similar characters in docstrings into newlines.
Preview style removes redundant parentheses around generator expressions.
Fixes misplaced or dropped inline comments around optional parentheses, comprehensions, and bracketed expressions.
Fixes parsing assignment magics when non-ASCII characters occur earlier on the line.
No longer inserts an empty line after a docstring when the range covers only the docstring, and preserves comments and blank lines outside requested ranges.
Respects the magic trailing comma in PEP 695 type parameter lists containing a
*TypeVarTupleor**ParamSpec.Fixes crashes when splitting
case case if ...patterns at very small line lengths.Stops dropping trailing commas from split single-element tuple lambda defaults and one-element subscripts.
Preserves CRLF endings on the skipped line instead of turning them into
\r\r\n.Avoids a crash when writing formatted code or diffs to a stdout without a
bufferattribute.Fixes unparseable output when a t-string replacement field contains a quote.
No longer emits a spurious warning when the runtime version is included in the flag.
Fixes unparseable output when the string body ends in an already-escaped double quote.
Preview style removes redundant parentheses around individual variables in unpacking targets.
Blackd returns HTTP 400 for an empty header or empty entry, and accepts optional whitespace around comma-separated versions and
pyi.Fixes unstable formatting when a subscript annotation contains an inline comment.
Corrects the version reported by published executables.
Preserves inline comments immediately before a
# fmt: skipline, avoiding AST equivalence failures.Returns HTTP 400 for source parse failures and reserves HTTP 500 for genuine internal safety errors.
Fixes blank lines being removed between a function and a decorated class in
.pyistub files.Fixes a crash when an f-string follows a
# fmt: offcomment inside brackets.Fixes
# fmt: skipbeing ignored in nestedifexpressions with parenthesizedinclauses.Preserves multiline compound statement headers when
# fmt: skipis placed on the colon line.Python 3.15 is now supported, though compiled wheels are not yet provided and performance may be slower than on existing Python versions.
Prevents the string merger from creating unsplittable long lines when a pragma comment follows the closing bracket.
Fixes incorrect splitting of if guards when a case pattern has a trailing comma.
Fixes a crash on standalone comments in lambda default arguments.
Black no longer double-decodes input, preventing corruption of non-UTF-8 files.
Disables multiprocessing in frozen environments to fix shutdown errors in PyInstaller builds on macOS.
Fixes a crash on unassigned long string literals with trailing commas, such as one-item tuples.
When the target Python version is newer than the running Python, Black emits a clear warning and an actionable error explaining that AST safety checks cannot parse newer syntax.
Preserves parentheses when type-ignore comments would otherwise be merged, preventing AST equivalence failures.
Fixes
# fmt: skipon one-liner declarations so the declaration is not incorrectly collapsed.Comments before a module docstring no longer cause it to be treated as a normal string.
Removes parentheses around multiple exception types in
exceptandexcept*clauses withoutas.Fixes how type expansions are split in generic functions.
black 2526 changes
Breaking changes 1
Black no longer supports running with Python 3.9.
New APIs and options 4
The GitHub Action accepts an
output-fileinput to write formatter output to a file for artifact capture and cleaner logs.Releases now include binaries for arm64 Linux.
Adds a simple Python client for sending formatting requests to blackd.
Adds an option to control caching behavior.
Behavior and default changes 5
Comments containing fmt directives preserve their exact formatting instead of being normalized.
This feature moves from
--unstableto--preview.The GitHub Action supports the major-version-only “stability” format for
required-versionwhen using pyproject.toml.The Vim plugin warns about unsupported Vim and Python versions independently.
When importing black fails, the Vim plugin prints the import paths.
Tooling 3
Black supports Python 3.14 as a target version.
Black can format the new Python 3.14 t-string syntax introduced by PEP 750.
Type comments are standardized to the form
# type: <value>.
Fixes and other changes 13
Fix a preview-style crash in
fix_fmt_skip_in_one_linerson annotated parameters.Releases now include arm64 Windows binaries and wheels.
Fix a possible crash when fmt: directives are not at the top level.
Comments preceding these blocks are no longer incorrectly removed, including Jupytext markdown cell comments.
Fix crashes when multiple skip comments are used in multi-part if-clauses, on string literals, or on dictionary entries with long lines.
In preview style, the directive now skips the line it is on rather than the following line.
Preview style no longer adds new lines after imports marked with this directive.
Fix a preview-style crash in
fix_fmt_skip_in_one_linerson with statements.Comments between
# fmt: offand# fmt: onare no longer reformatted.The preview feature now respects
# fmt: skipfor compound statements with semicolon-separated bodies.Fixes an issue with how line breaks are inserted in Python 3.12 generics syntax.
When formatting is excluded from stdin piped through a command, unchanged content is written to stdout.
The Vim plugin now handles virtualenvs that use a different Python version.