`# fmt: skip` on an opening bracket alone makes `if`, `while`, `for` and `with` headers fail to parse
Describe the bug
On main, a # fmt: skip on the opening line alone of a parenthesized if, while, for or with header raises InvalidInput. Released 26.5.1 formats the same input fine, so this is an unreleased regression.
To Reproduce
import black
src = "if ( # fmt: skip\n cond\n):\n pass\n"
compile(src, "<input>", "exec") # succeeds
black.format_file_contents(src, fast=False, mode=black.Mode())InvalidInput: cannot parse: 3:1
)
^
ParseError: bad inputwhile (, for i in ( and with ( behave the same. def, class and a plain call are unaffected on main.
Expected behavior
Format successfully, as 26.5.1 does.
Environment
Black main at 20622e12; Ubuntu, CPython 3.12.3; default Mode(), fast=False.
Additional context
git bisect across the 105 commits in 26.5.1..20622e12 points at 7e8ef6bc (#5144). Its parent 650983f7 formats the input; 7e8ef6bc raises. _force_standalone_comment_split splits at the standalone-comment boundary, separating ) from the : that has to stay on that line.
The behaviour is inverted across the release boundary: on 26.5.1 these four succeed while def, class and call forms raise ASTSafetyError. #5161 fixed those, and this appeared.
#5397 and #5401 are the paired-directive form of the same split; #5401 does not address this one.
Claude Opus 5 assisted with the bisect and reproduction.
Source: psf/black