class Rectangle(Blob):
def __init__(self, width, height,
color='black', emphasis=None, highlight=0):
So that is the official answer. Personally I detest this approach, in which continuation lines have leading whitespace that doesn't correspond to any real indentation level. My approach would be:
Personally I also used to come up with the same solution as @BrenBarn 's second style. I like its way to properly represent the indentation of function parameters AND its implementation, albeit that "unhappy face" is somewhat unusual to some other people.
Nowadays, PEP8 specifically gives an example for such case, so perhaps the mainstream is going to adapt that style:
# Add 4 spaces (an extra level of indentation)
# to distinguish arguments from the rest.
def long_function_name(
var_one, var_two, var_three,
var_four):
print(var_one)
We can of course go one step further, by separating each parameter into its own line, so that any future addition/deletion of parameter would give a clean git diff:
# Add 4 spaces (an extra level of indentation)
# to distinguish arguments from the rest.
def long_function_name( # NOTE: There should be NO parameter here
var_one,
var_two,
var_three,
var_four, # NOTE: You can still have a comma at the last line
): # NOTE: Here it aligns with other parameters, but you could align it with the "def"
print(var_one)
Having each argument on one line makes it very simple to use git diffs, since changing one variable will only show that change. If you have more than one argument on each line, it's gonna be more visually annoying later.
Notice that the trailing comma after the last argument makes it easier to add or remove an argument later, while also conforming to the PEP 8's Trailing Comma Convention, and yielding a better git diff later.
One of the reasons I really dislike the "align the arguments with the opening parenthesis" paradigm is that it doesn't yield easily maintainable code.
The major reason it is a bad practice is that if you change the name of the function (or if it is too long), you're going to have to re-edit the spacing on all the arguments' lines, which is not at all scalable, though it may be (sometimes) (subjectively) prettier.
The other reason, closely related to the one immediately above, is about metaprogramming. If the codebase becomes too big, you will eventually find yourself needing to program changes to the code file itself, which might become hell if the spacing on arguments is different for each function.
Most editors, once the parentheses are open and you press enter, will open a new line with a tab and shove the closing parenthesis to the next line, untabbed. So, formatting the code this way is very quick and kind of standardized. For instance, this formatting is very common in JavaScript and Dart.
Lastly, if you think having each argument is too unwieldy because your function might have a lot of arguments, I would say that you're compromising easy formatting of your code due to rare exceptions.
Don't legislate by exceptions.
If your function has a lot of arguments, you're probably doing something wrong. Break it into more (sub)functions and (sub)classes.
3. Anyway...
A good convention is better than a bad one, but it's much more important to enforce one than be unnecessarily picky about them.
Once you've decided to use a standard, share your decision with your colleagues and use an automated formatter — for example, Prettier is a popular choice for JavaScript in VS Code; and the Dart language has standardized one globally: dartfmt — to enforce it consistently, diminishing the need of manual editing.