Skip to content

Incorrect formatting of comments in match statement for tuple without parentheses #8091

@doraut

Description

@doraut

Version: 0.1.1
Command: ruff format --isolated example.py
Playground: Example

Example

def fizzbuzz(n):
    match n % 3, n % 5:
        case 0, 0:
            # n is divisible by both 3 and 5
            print("FizzBuzz")
        case 0, _:
            # n is divisible by 3, but not 5
            print("Fizz")
        case _, 0:
            # n is divisible by 5, but not 3
            print("Buzz")
        case _:
            print(n)

This is formatted to

def fizzbuzz(n):
    match (
        n % 3,
        n % 5,
        # n is divisible by both 3 and 5
        # n is divisible by 3, but not 5
        # n is divisible by 5, but not 3
    ):
        case 0, 0:
            print("FizzBuzz")
        case 0, _:
            print("Fizz")
        case _, 0:
            print("Buzz")
        case _:
            print(n)

Adding parentheses around the matched tuple (match n % 3, n % 5 -> match (n % 3, n % 5)) results in expected formatting.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingformatterRelated to the formatter

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions