Black: Content unnecessarily split onto multiple lines

Created on 30 Nov 2019  路  4Comments  路  Source: psf/black

Describe the bug A clear and concise description of what the bug is.

Black is spreading content across multiple lines that would easily fit on a single line. In particular the first example from the "how black wraps lines" in the docs here is not reproduced with black==19.10b0

To Reproduce Steps to reproduce the behavior:

  1. Make a Python file (demo.py) containing the snippet from the docs
j = [1,
     2,
     3,
]
  1. Run black demo.py (default arguments)
  2. Resulting file is formatted as
j = [
    1,
    2,
    3,
]

Expected behavior A clear and concise description of what you expected to happen.

According to the docs, and as was the case in earlier versions of Black (e.g. 19.3b0) output should be

j = [1, 2, 3]

Personally I think this is a much more reasonable output in this case.

Environment (please complete the following information):

  • Version: 19.10b0
  • OS and Python version: macOS, Python 3.7.4

Does this bug also happen on master?

Yes. See here

not a bug

Most helpful comment

I see, thanks for changing that example and for clarifying that this behaviour is expected.

Do you have any suggestions about how to make this behavior clearer in the docs?

Is it actually documented? Despite searching I couldn't find a description of this behaviour in the docs. I would have maybe expected something in either the section on trailing commas or how black wraps lines. The only place I found any mention of it was the changelog. Some mention of this behaviour in either (both?) of those sections of the docs would be helpful I think.

All 4 comments

A trailing comma forces the dictionary literal to be expanded across multiple lines. If you remove the comma after 3 you'll get the output you expect. Do you have any suggestions about how to make this behavior clearer in the docs?

I've fixed the example in the doc itself

I see, thanks for changing that example and for clarifying that this behaviour is expected.

Do you have any suggestions about how to make this behavior clearer in the docs?

Is it actually documented? Despite searching I couldn't find a description of this behaviour in the docs. I would have maybe expected something in either the section on trailing commas or how black wraps lines. The only place I found any mention of it was the changelog. Some mention of this behaviour in either (both?) of those sections of the docs would be helpful I think.

Since March 4th, there now is documentation on this specific behaviour and feature. This is the commit that introduces it: https://github.com/psf/black/commit/e253f1260d234ff925cbdbb77c140da8aa81190b.

This issue is now resolved. @tcbegley, thank you for opening the issue!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lig picture lig  路  84Comments

bofm picture bofm  路  72Comments

spapanik picture spapanik  路  23Comments

Kristinita picture Kristinita  路  28Comments

odormond picture odormond  路  21Comments