black splits argument list over several lines, even though code requires <88 characters

Created on 4 Sep 2020  路  2Comments  路  Source: psf/black

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

black 20.8b1 formats a line differently than 19.10b0, both of them incorrectly splitting a line that fits into 69 characters into 5 and 3 lines, respectively.

To Reproduce Steps to reproduce the behavior:

  1. Take this file
parser.add_argument(
    "pdf", nargs="+", help="pdf to run inference on",
)
  1. Run _Black_ on it with these [default] arguments

  2. See error

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

Code should be condensed to a single line (<88 characters). Instead, it is split across 5 lines, into

parser.add_argument(
    "pdf",
    nargs="+",
    help="pdf to run inference on",
)

Environment (please complete the following information):

  • Version: 20.8b1, master
  • OS and Python version: MacOS/Python 3.8.1, Linux/Python 3.8.5

Does this bug also happen on master?

Yes, see in the online formatter

Additional context Add any other context about the problem here.

Oddly, version 19 produced the original code, so this was discovered when code that passed the black pre-commit hook (running 19.10b0) failed in CI (running black 20.8b1) -- but it seems like both versions incorrectly split across multiple lines, just differently from each other.

not a bug trailing comma

All 2 comments

This is expected behaviour and a somewhat new feature. In 19.10b0 we introduced the "magic trailing comma" in which you can tell Black to always explode collections, function signatures and calls, and more. Then in 20.08b0 and 20.08b1 we fixed it to work properly in most cases. So that's why there is a formatting difference between the versions. There are still some edge cases, but the feature is generally usable. You can read the documentation on it for more information.

Hope that helps!

Thank you!

Was this page helpful?
0 / 5 - 0 ratings