Skip to content

Fail to parse multiline case statement with # fmt: skip #5122

@DrGFreeman

Description

@DrGFreeman

Describe the bug

Parsing a multiline case statement with # fmt: skip fails with black >= 26.

To Reproduce

For example, take this code:

# file.py
match (method, *path.split("/")):

    case ("GET", "parent", _, "resource", resource_id) \
            | ("GET", "resource", resource_id):  # fmt: skip
        pass

    case _:
        pass

And run it with these arguments:

$ black file.py

The resulting error is:

error: cannot format file.py: Cannot parse: 6:42: | ("GET", "resource", resource_id): # fmt: skip

Expected behavior

The multi-line case statement remains unchanged.

Environment

  • Black's version: 26.1.0 and up (no issue with 25.12.0).
  • OS and Python version: [Windows/Python 3.13.2] -->

Metadata

Metadata

Assignees

No one assigned

    Labels

    T: bugSomething isn't working
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions