Skip to content

Black deviation with if x in some comprehension  #8090

@philippgl

Description

@philippgl

I just fund a small difference with the black formatter.

  • A minimal code snippet that reproduces the bug.

This is the black formatted example (imho, this also looks nicer):

def some_function():
    if "root" not in (
        long_tree_name_tree.split("/")[0]
        for long_tree_name_tree in really_really_long_variable_name
    ):
        msg = "Could not find root. Please try a different forest."
        raise ValueError(msg)

which gets reformatted to:

def some_function():
    if (
        "root"
        not in (
            long_tree_name_tree.split("/")[0]
            for long_tree_name_tree in really_really_long_variable_name
        )
    ):
        msg = "Could not find root. Please try a different forest."
        raise ValueError(msg)
  • The command you invoked (e.g., ruff /path/to/file.py --fix), ideally including the --isolated flag.
ruff format --isolated filename.py
  • The current Ruff settings (any relevant sections from your pyproject.toml).

None. This is a standalone script.

  • The current Ruff version (ruff --version).

ruff 0.0.292
ruff 0.1.0

(I tried it with both versions)

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