3 ms·
That example isn't quite how Black works, because Black only separates parentheses from their contents if the contents would be longer than a single line. So an
by BugsJustFindMe 5y ago
That example isn't quite how Black works, because Black only separates parentheses from their contents if the contents would be longer than a single line. So any function with one line of arguments will look exactly like your first example.
I think also that the comments you put there are mistaken because functions have more logical sections than you're recognizing here. Function definitions always follow the form `<label>(<arguments>): <body>`. You say "visually inside" in two of your comments, but in actuality they are two different things entirely because one is talking about the body section and one is talking about the arguments section, and your first example just skips over the arguments section as if it either doesn't exist or isn't its own very important part of the function definition.
A more thorough example set without yet expanding the arguments would be:
def f(x # inside of arguments section): # outside of arguments section
Pass # inside of body section
vs
def f(
X # inside of arguments section
): # outside of arguments section
pass # inside of body section
or if one prefers to make the "outside" parts nonexplicit,
def f(x # inside of arguments section):
Pass # inside of body section
vs
def f(
X # inside of arguments section
):
pass # inside of body section
The indent+dedent says "this is the section". But again, Black only does anything if your argument section runs longer than a single line.
It's really not about def f(x), because Black does exactly the thing you want for f(x). It's about
def f(abesessefe, dedddf_asdf, readfsefsef_afsefse, foreard_aree_aers=True,
arese_mars_mares=None, maresd_des_reeebo='17'):
pass
vs
def f(
| abesessefe,
| dedddf_asdf,
| readfsefsef_afsefse,
| foreard_aree_aers=True,
| arese_mars_mares=None,
| maresd_des_reeebo='17'
):
pass
The point of what Black does is that in the second case the dedented section terminator `)` is always going to be at the same column as the def if the arguments run past one line, so it will always be easy to find and your arguments will also be a lot easier to read.