Skip to content

Pattern matching pattern does not follow line-length #3403

@grantroch

Description

@grantroch

Describe the bug

A pattern matching pattern without parentheses does not get reformatted according to the line-length. This does get formatted if the pattern is surrounded by parentheses.

To Reproduce

The following should wrap the first pattern.

import enum


class AnimalEnumeration(enum.IntEnum):
    ELEPHANT = 0
    GIRAFFE = 1
    AARDVARK = 2
    GOLDFISH = 3


def match_animal():
    x = AnimalEnumeration.ELEPHANT
    match x:
        case AnimalEnumeration.ELEPHANT | AnimalEnumeration.GIRAFFE | AnimalEnumeration.AARDVARK | AnimalEnumeration.GOLDFISH:
            return True
        case _:
            return False


if __name__ == "__main__":
    print(match_animal())`

And run it with these arguments:

$ black file.py --target-version py310

Expected behavior

I would expect this to get wrapped like a variable does.

        case (
            AnimalEnumeration.ELEPHANT
            | AnimalEnumeration.GIRAFFE
            | AnimalEnumeration.AARDVARK
            | AnimalEnumeration.GOLDFISH
        ):
            return True

Environment

  • Black's version: black, 22.10.1.dev24+gd4a8564 (compiled: no) (main)
  • OS and Python version: Windows 10, Python (CPython) 3.10.6

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