PEP 8 regarding hanging indent:
When using a hanging indent the following considerations should be applied; there should be no arguments on the first line and further indentation should be used to clearly distinguish itself as a continuation line.
Is there any explicit documentation about about "sub-arguments"? For example:
some_method(argument_one, argument_two, argument_three=[
'parameter_one',
'parameter_two',
'parameter_three',
])
As opposed to:
some_method(
argument_one,
argument_two,
argument_three=[
'parameter_one',
'parameter_two',
'parameter_three',
]
)
Preferably links to official discussions only.
PEP 8, sometimes spelled PEP8 or PEP-8, is a document that provides guidelines and best practices on how to write Python code. It was written in 2001 by Guido van Rossum, Barry Warsaw, and Nick Coghlan. The primary focus of PEP 8 is to improve the readability and consistency of Python code.
A Hanging indent, also known as a second line indent, sets off the first line of a paragraph by positioning it at the margin, and then indenting each subsequent line of the paragraph.
Hanging indents are used in the works cited or bibliography of MLA, APA, Chicago, and various other citation styles. They allow the reader to easily see the breaks between separate citations and quickly scan a works cited or bibliography for author names.
Indentation refers to the spaces at the beginning of a code line. Where in other programming languages the indentation in code is for readability only, the indentation in Python is very important. Python uses indentation to indicate a block of code.
From PEP 8's "Other Recommendations" section:
Compound statements (multiple statements on the same line) are generally discouraged.
With this recommendation in mind, your 2nd example is probably more in line with the PEP 8 style guide, as it avoids compounding the method invocation and list construction on the same line. The 2nd example reads a little easier too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With