Black: Explode function calls?

Created on 18 May 2018  路  6Comments  路  Source: psf/black

Should black explode function calls like it does collection literals? Should this example from the README:

# in:

TracebackException.from_exception(exc, limit, lookup_lines, capture_locals)

# out:

TracebackException.from_exception(
    exc, limit, lookup_lines, capture_locals
)

actually output:

TracebackException.from_exception(
    exc,
    limit,
    lookup_lines,
    capture_locals,
)

Operating system: OS X 10.11.6
Python version: 3.6.5
Black version: 18.5b0
Does also happen on master: as of 7395f55564a689a28db5ab3f82c079f7fc40eadf

design

Most helpful comment

This formatting minimizes vertical whitespace spent on those constructs. Our monitors are already rather wider than taller.

Sometimes monitors can be rotated 90 degrees. Some of our team members do that.

You wouldn't want cases that fit in a single line be exploded, would you?

I would, personally.

I don't find the following readable for example, but black currently enforces this (hoisting variable definitions might be a "solution" to this case):

image

All 6 comments

One more example with 3 different results for different lengths

In:

router.register(r'inspection-categories', InspectionCategoryViewSet, base_name='inspection-categories')
router.register(r'tasks', TaskViewSet, base_name='tasks')
router.register(r'inspection-results', InspectionResultViewSet, base_name='inspection-results')

Out:

router.register(
    r"inspection-categories",
    InspectionCategoryViewSet,
    base_name="inspection-categories",
)
router.register(r"tasks", TaskViewSet, base_name="tasks")
router.register(
    r"inspection-results", InspectionResultViewSet, base_name="inspection-results"
)

Function signatures, class hierarchies, function calls, comprehensions and other parenthesized expressions still use the three-way indentation mechanism:

  • fit on a line; or
  • fit all bracket contents on a one-indented line; or
  • explode one element per line.

This formatting minimizes vertical whitespace spent on those constructs. Our monitors are already rather wider than taller. You wouldn't want cases that fit in a single line be exploded, would you? So, for cases where moving all arguments to its own one-indented line is enough for them to fit a single line, we do that.

I decided to allow exploding data structures right away since examples from the standard library, attrs, Twisted codebase, as well as Warehouse, convinced me that data is overwhelmingly of regular shape (so exploded variants read better). On the other hand, signatures and calls aren't.

I'd like more feedback before changing anything here.

This formatting minimizes vertical whitespace spent on those constructs. Our monitors are already rather wider than taller.

I agree with that (thought it still interesting to me that we use arguments like that but still set default line length to values around 80 chars)

My main concern with the provided example is that it's harder to read a mix of three styles when they are going line after line (like in django urls.py)

We won't be doing this.

This formatting minimizes vertical whitespace spent on those constructs. Our monitors are already rather wider than taller.

Sometimes monitors can be rotated 90 degrees. Some of our team members do that.

You wouldn't want cases that fit in a single line be exploded, would you?

I would, personally.

I don't find the following readable for example, but black currently enforces this (hoisting variable definitions might be a "solution" to this case):

image

You wouldn't want cases that fit in a single line be exploded, would you?

I would, personally.

+1

My main concern with the provided example is that it's harder to read a mix of three styles when they are going line after line (like in django urls.py)

Same, readability suffers (as well as the "small diffs" leading principle of black).
Would be great two have two modes, not an awkward third intermediary.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

decibyte picture decibyte  路  3Comments

kissgyorgy picture kissgyorgy  路  3Comments

uranusjr picture uranusjr  路  3Comments

dimaqq picture dimaqq  路  3Comments

J0 picture J0  路  3Comments