Skip to content

Black doesn't split too long for-in in list comprehension #3498

@AdeliManesh

Description

@AdeliManesh

Describe` the bug
In my python file a line with more than 80 characters exists but black doesn't split the line into multi lines due the line length constraint.

To Reproduce
the is my "test.py" file.

graph_path_expressions_in_local_constraint_refinements = [
	graph_path_expression
	for refined_constraint in self._local_constraint_refinements.values()
	if refined_constraint is not None
	for graph_path_expression in refined_constraint.condition_as_predicate.variables
]

Run Black:$ black -l 79 --preview test.py
All done! ✨ 🍰 ✨

Expected behavior

This is the result which i get from yapf and it is ok for me.

graph_path_expressions_in_local_constraint_refinements = [
	graph_path_expression for refined_constraint in
		self._local_constraint_refinements.values()
		if refined_constraint is not None for graph_path_expression in
		refined_constraint.condition_as_predicate.variables
]

but black doesn't make any changes and gives the below result:

graph_path_expressions_in_local_constraint_refinements = [
	graph_path_expression
	for refined_constraint in self._local_constraint_refinements.values()
	if refined_constraint is not None
	for graph_path_expression in refined_constraint.condition_as_predicate.variables
]

Environment

  • Black's version: black, 22.12.0 (compiled: yes)
  • OS and Python version: Ubuntu 18.04/Python 3.8.16

Metadata

Metadata

Assignees

No one assigned

    Labels

    F: linebreakHow should we split up lines?F: linetoolongBlack makes our lines too longT: bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions