pythonpep8

PEP8 hanging indent specification


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 official 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',
        ]
    )

Solution

  • 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.