Skip to content

Can't format valid python file: "Invalid document: Expected end tag of kind Group but found Indent." #25397

@Castavo

Description

@Castavo

Summary

In our code base we have a specific piece of code which is legit but seems to throw off ruff format.

It gives the error message: error: Failed to format [path/to/file.py]: Invalid document: Expected end tag of kind Group but found Indent.

I reproduced it with this snippet, which can also be found on the playground

class CantFormat:
    args: list[int]

    def __str__(self) -> str:
        return (
            "first string"
            f"list of args long={list(map(lambda arg: str(arg), self.args))})"
        )

ruff format does not fail when the two lines are short enough to be formatted into a single line.

Version

ruff 0.15.14 (9ad2da3 2026-05-21)

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingformatterRelated to the formatter

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions