fix: pin the Black target version to the minimum supported Python - #613
Merged
Conversation
Black infers its target versions from `requires-python`. Because that
bound is open-ended (`>=3.11`), it expanded to every version Black
knows about, including py315:
target_version: ['py311', 'py312', 'py313', 'py314', 'py315']
Black's safety check re-parses its output with the stdlib `ast` module
using the highest target version, which no interpreter from 3.11 to 3.14
can do. That made every lint job emit:
Warning: Python 3.14 cannot parse code formatted for Python 3.15.
Formatting was never affected, since Black only emits syntax common to
all targets and so was already formatting for the 3.11 floor; `--diff`
output is byte-identical between py311 and py315. What was lost is the
AST equivalence check that guards against Black corrupting code.
Pinning the floor explicitly restores that check and silences the
warning with no formatting change. This needs bumping alongside any
future increase to `requires-python`.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5qn7KvBztnwaRTFoL9KNo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Every
Lintjob onbetaemits a warning, on all four matrix legs (3.11–3.14):Latest
betarun: 31718873837. It also reproduces locally viajust lint.Cause
There was no
[tool.black]section, so Black inferred its target versions fromproject.requires-python. Because that bound is open-ended (>=3.11), it expanded to every version Black knows about:Black's safety check re-parses its own output with the stdlib
astmodule, using the highest target version. No interpreter from 3.11 through 3.14 can produce a 3.15 AST, so the check is skipped and the warning is printed.Impact
Formatting was never wrong, and lint was never failing. Black only emits syntax common to all of its targets, so it was already formatting for the 3.11 floor. Verified two ways:
black --diff --target-version py315 .and--target-version py311 .produce byte-identical output across the repo.What was actually lost is the AST equivalence check — Black's guard against its own output changing program semantics. That guard was silently off for every lint run.
Change
Pinning the floor explicitly restores the safety check and silences the warning, with no formatting change.
Verification
Note for reviewers
This value needs bumping alongside any future increase to
requires-python. The alternative — leaving the warning in place — keeps one less thing to maintain but leaves Black's safety check disabled, so pinning seemed the better trade.Generated by Claude Code