Skip to content

match_continuation breaks on form feed, making TC004 introduce a syntax error #19175

@dscorbett

Description

@dscorbett

Summary

match_continuation does not recognize U+000C FORM FEED as white space. That makes the fix for runtime-import-in-type-checking-block (TC004) ignore a line continuation character after a form feed after a TYPE_CHECKING import, introducing a syntax error. Example:

$ cat >tc004.py <<'# EOF'
from typing import TYPE_CHECKING\

if TYPE_CHECKING: import builtins
builtins.print("!")
# EOF

$ ruff --isolated check tc004.py --select TC004 --unsafe-fixes --diff 2>&1 | grep error:
error: Fix introduced a syntax error. Reverting all changes.

There is a form feed before the backslash in that example. Some browsers hide control characters. Hopefully it’s still there if you copy and paste it.

Version

ruff 0.12.2 (9bee837 2025-07-03)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixesRelated to suggested fixes for violations

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions