Implement the wrap_comprehension_in preview style from Black

Summary
--

This PR implements the `wrap_comprehension_in` style added in
https://github.com/psf/black/pull/4699. This wraps `in` clauses in
comprehensions if they get too long. Using some examples from the upstream
issue, this code:

```py
[a for graph_path_expression in refined_constraint.condition_as_predicate.variables]

[
    a
    for graph_path_expression
    in refined_constraint.condition_as_predicate.variables
]
```

is currently formatted to:

```py
[
    a
    for graph_path_expression in refined_constraint.condition_as_predicate.variables
]

[
    a
    for graph_path_expression in refined_constraint.condition_as_predicate.variables
]
```

even if the second line of the comprehension exceeds the configured line length.

In preview, black will now break these lines by parenthesizing the expression
following `in`:

```py
[
    a
    for graph_path_expression in (
        refined_constraint.condition_as_predicate.variables
    )
]

[
    a
    for graph_path_expression in (
        refined_constraint.condition_as_predicate.variables
    )
]
```

I actually kind of like the alternative formatting mentioned on the original
Black issue and in our #12870 which would be more like:

```py
[
    a
    for graph_path_expression
	in refined_constraint.condition_as_predicate.variables
]
```

but I think I'm in the minority there.

Test Plan
--

Existing Black compatibility tests showing fewer differences
This commit is contained in:
Brent Westbrook
2025-10-20 10:43:40 -04:00
parent e1cada1ec3
commit 615e1a17eb

Diff Content Not Available