You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is nice - the function has an unwieldy return type, and presented on one line, it is not very unreadable.
This multi-line version is also better for a git diff.
Now the if the function has an arg, the magic comma will take us from this:
The return type's trailing comma is ignored, and it stays on one huge line
This also produces a flake8 error E231 (missing whitespace after ,).
Desired style
I can think of two desired results.
First (preferred):
deffn(arg) ->Tuple[ # single arg, no need for additional newlineTuple[Value, Value, Value],
Tuple[Value, Value, Value],
Tuple[Value, Value, Value],
Tuple[Value, Value, Value],
]:
...
Second:
deffn(
arg, # Extra newline - not really necessary, but more consistent with example below
) ->Tuple[
Tuple[Value, Value, Value],
Tuple[Value, Value, Value],
Tuple[Value, Value, Value],
]:
...
This second version is consistent with how the function would look when the return type grows and exceeds line length.
It's not ideal that the arguments are exploded unnecessarily, but it seems like this is possibly a separate topic.
deffn(
arg,
) ->Tuple[
Tuple[Value, Value, Value],
Tuple[Value, Value, Value],
Tuple[Value, Value, Value],
Tuple[Value, Value, Value], # Here it cannot fit on one line
]:
...
The text was updated successfully, but these errors were encountered:
Whereas #1671 has only the final comma taking effect, this has only the initial comma (inside the function args) taking effect. Not sure, but it seems like these might be different.
Describe the style change
For a function with no args, magic trailing comma lets us control how the return type looks.
However, if we add an arg, the magic trailing comma is ignored, and the return type stays on one huge line.
Instead, it should be split across lines.
Examples in the current Black style
For brevity, suppose all snippets begin with
Consider the case of
--line-length 120
. Length is not a factor here; in all cases, the entire definition could fit on one line.With no arguments to
def fn()
, adding the comma will take us from this:... to this:
This is nice - the function has an unwieldy return type, and presented on one line, it is not very unreadable.
This multi-line version is also better for a git diff.
Now the if the function has an arg, the magic comma will take us from this:
... to this:
Notice the two changes that were made.
arg
receives a trailing comma and its own lineThis also produces a flake8 error
E231
(missing whitespace after,
).Desired style
I can think of two desired results.
First (preferred):
Second:
This second version is consistent with how the function would look when the return type grows and exceeds line length.
It's not ideal that the arguments are exploded unnecessarily, but it seems like this is possibly a separate topic.
The text was updated successfully, but these errors were encountered: