Black applies uniform horizontal and vertical whitespace by ignoring previous formatting.
Horizontal Whitespace
Rules follow pycodestyle recommendations.
Vertical Whitespace
Black attempts to render one full expression or simple statement per line.
- If it fits the line length: It stays on one line.
- If it exceeds the line length: Black looks at the first outer matching brackets and puts the contents on a separate indented line. If it still doesn't fit, it decomposes the expression further, indenting matching brackets at each level.
- Comma-separated contents: For argument lists, dict literals, etc., Black first tries to keep them on the same line with matching brackets. If that fails, it puts every element on its own line.
- Data structures and imports: If a data structure literal (tuple, list, set, dict) or a
from ... import ... line cannot fit the allotted length, it is always split into one element per line. This minimizes git diffs and improves readability.
# in:
ImportantClass.important_method(exc, limit, lookup_lines, capture_locals, extra_argument)
# out:
ImportantClass.important_method(
exc, limit, lookup_lines, capture_locals, extra_argument
)