Skip to content

Line too long: Many cases in case block #3850

@JelleZijlstra

Description

@JelleZijlstra

Describe the bug

Match patterns with lots of |-delimited alternatives are not split into multiple lines.

To Reproduce

% cat longmatch.py 
match x:
    case "abcd" | "abcd" | "abcd" | "abcd" | "abcd" | "abcd" | "abcd" | "abcd" | "abcd" | "abcd" | "abcd" | "abcd" | "abcd" | "abcd" | "abcd":
        pass
% black -t py311 longmatch.py --diff
All done! ✨ 🍰 ✨
1 file would be left unchanged.

(Note the line is 142 characters long)

Expected behavior

I want it to reformat to:

match x:
    case (
        "abcd"
        | "abcd"
        | "abcd"
        | "abcd"
        | "abcd"
        | "abcd"
        | "abcd"
        | "abcd"
        | "abcd"
        | "abcd"
        | "abcd"
        | "abcd"
        | "abcd"
        | "abcd"
        | "abcd"
    ):
        pass

Black does this already if you manually add parentheses around the whole sequence of alternatives.

Environment

  • Black's version: 23.7.0
  • OS and Python version: macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    F: linetoolongBlack makes our lines too longT: bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions