Skip to content

if clauses in match-case blocks aren't reformatted to fit the line width limit #3793

@alexander-c-b

Description

@alexander-c-b

Describe the bug

if clauses in match-case blocks in are not reformatted when the line length is above the maximum length set.

To Reproduce

Take this code, where the second line is 99 characters (11 characters above the horizontal limit):

match "test":
    case "test" if "any long condition" != "another long condition" and "this is a long condition":
        print("Test")

And try formatting it:

$ black file.py

Black leaves the file unchanged:

All done! ✨ 🍰 ✨
1 file left unchanged.

Expected behavior

Black should reformat the file as:

match "test":
    case "test" if (
        "any long condition" != "another long condition" and "this is a long condition"
    ):
        print("Test")

Environment

  • Black's version: 23.7.0
  • OS and Python version: Ubuntu Linux 22.04 (running on the Windows Subsystem for Linux) / Python 3.10.4

Additional context

This appears to happen regardless of the line length. Also, interestingly, if parentheses are added around the boolean expression manually, Black does format the file correctly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    F: linetoolongBlack makes our lines too longS: acceptedThe changes in this design / enhancement issue have been accepted and can be implementedT: bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions