-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Long arrays wrapped unnecessarily on multiple lines #1281
Description
Versioning
Black 19.10b0, OS Windows 10 1803 and Python 3.7.2.
Is your feature request related to a problem? Please describe.
The problem is related to how black currently wraps arrays. For instance, smaller arrays such as [1,2,3] formats correctly to [1, 2, 3] while staying on a single line. Longer arrays, such as

becomes

Which uses too many lines. Note how a comma , is automatically added at the end of the array, thus likely triggering a phenomenon of this type. Removing the comma changes nothing, as it simply comes back. See ie. the black playground.
Describe the solution you'd like. I wish to use black for formatting, but with wrapping behavior similar to (or equal to) that of autopep8's formatting for such arrays as described. Which gives:

Describe alternatives you've considered
- Use
# fmt: offbefore a code block, and# fmt: onafter. While this works, the array a) remains unformatted and b) stays only on one line that introduces a scrollbar which must be used to check the full content - Use Excel file to store longer numbered arrays, and importing them with ie. pandas to keep data entry on 1-2 lines. I find this option inconvenient for arrays of intermediate lengths (such as the longer array displayed) that a) does not fit on a single line and b) are too short for it to make sense to store it in an Excel file (ie. when setting up test arrays on-the-fly)
- Reverting back to version
18.4a0appear to be equivalent tofmteffect, primarily because formatting then appears to not be applied at all. I have not explored the consequences this has with other formatting behavior not related to this test case. The next version,18.4a1, produces the exact same behavior as the behavior of19.10b0(also with the extra comma at the end of the then vertically formatted array)
settings.json
{
"python.pythonPath": ".venv\\Scripts\\python.exe",
"editor.acceptSuggestionOnEnter": "off",
"python.formatting.provider": "black",
//"python.formatting.provider": "autopep8",
"editor.formatOnSave": true,
"python.formatting.blackArgs": [
"--line-length",
"88"
],
"python.formatting.autopep8Args": [
"--max-line-length",
"88",
"--experimental"
]
}