Fix unstable formatting with a comment and an implicitly concatenated last argument #5587
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.40) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 303 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.342
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #5587"
general
weight: 0.35
nk-batman21
Description
On
main, Black fails on this code with "INTERNAL ERROR: Black ... produced different code on the second pass of the formatter" and exits with 123:It happens when a comment follows an argument and the last argument is an implicitly concatenated string. The arguments fit on one line inside the call, so the first pass joins them and prints the comment at the end, after the strings. On the next run the comment belongs to the last string, which keeps the strings apart, and the split adds a trailing comma that is printed before the comment. The run after that joins the strings again. With
--skip-magic-trailing-commathe output is stable, but the comment ends up after thehelp=argument.contains_implicit_multiline_string_with_commentsnow also returns True when the line ends with an implicitly concatenated string and has a comment anywhere, since joining the line would print that comment right after the strings. The line is then split by delimiter, so the comment stays on the argument it was written after, in both modes:Already formatted code doesn't change.
Ran:
pytest tests --run-optional no_jupyter, then the jupyter tests with the extra installed,black --check ., isort, flake8 and prettier at the pre-commit versions, and mypy (no new findings).Checked: about 5,600 CPython 3.14 stdlib statements with a comment injected near an implicit concatenation, and another 5,600 with
# type: ignore/# noqacomments, formatted with and without the patch in default,-C,-l 79/100/120, preview and unstable modes (the second set without-l 100and unstable). Unstable results went from 111 and 91 to 0; the only other changed outputs are 12 and 15-Ccases where the comment now stays on its argument. Re-formatting the output ofmainwith the patch changes nothing, and about 1,700 stdlib files format identically.Checklist - did you ...
--previewstyle, following the stability policy?CHANGES.mdif necessary?