Skip to content

Structural Pattern Matching (match case statement) with Or patterns ( | ) fail to break long code into multiple lines #3726

@jackjyq

Description

@jackjyq

Describe the style change

Examples in the current Black style

match status:
    case ThisIsAnExampleStringEnum.this_is_example_status_one | ThisIsAnExampleStringEnum.this_is_example_status_two | ThisIsAnExampleStringEnum.this_is_example_status_three:
        print("ok")
    case _:
        print("not ok")

Desired style

match status:
    case (
        ThisIsAnExampleStringEnum.this_is_example_status_one
        | ThisIsAnExampleStringEnum.this_is_example_status_two
        | ThisIsAnExampleStringEnum.this_is_example_status_three
    ):
        print("ok")
    case _:
        print("not ok")

Additional context

The complete code example:

from enum import Enum


class ThisIsAnExampleStringEnum(Enum):
    this_is_example_status_one = "one"
    this_is_example_status_two = "two"
    this_is_example_status_three = "three"


status = ThisIsAnExampleStringEnum.this_is_example_status_two

match status:
    case ThisIsAnExampleStringEnum.this_is_example_status_one | ThisIsAnExampleStringEnum.this_is_example_status_two | ThisIsAnExampleStringEnum.this_is_example_status_three:
        print("ok")
    case _:
        print("not ok")

Metadata

Metadata

Assignees

No one assigned

    Labels

    T: styleWhat do we want Blackened code to look like?

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions