Skip to content

Formatting adds unnecessary parentheses to long patterns with as captures #17796

@brandtbucher

Description

@brandtbucher

Summary

See this playground link, where I've put the expected formatting going in, and you can see the unexpected formatting coming out:

https://play.ruff.rs/81f62f2d-6858-43eb-8a9b-67dcebdc56f6?secondary=Format

It appears that "grouping" characters in patterns like (), [], and {} aren't being used correctly when they are followed by a capture (as name). Instead of breaking on these, the entire pattern (including the capture) is wrapped in parentheses and indented.

First encountered in https://github.com/python/cpython/pull/133123/files#r2071981099.

Version

0.11.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingformatterRelated to the formatter

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions