psf / black

The uncompromising Python code formatter
https://black.readthedocs.io/en/stable/
MIT License
38.75k stars 2.43k forks source link

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

Open AdeliManesh opened 1 year ago

AdeliManesh commented 1 year ago

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

felix-hilden commented 1 year ago

Thanks for submitting this! Here's a simplified case on the playground.

Pathfinder216 commented 1 year ago

This is also a problem with dictionary comprehensions. Here's another playground case showing both.