PEP8 - contradiction between E129 and E127 / E128

According to PEP standards, indentation must come before binary operators. In addition, multi-line conditions must be enclosed in parentheses to avoid using backslashes before newlines. These two conventions lead to the following situation.

if (long_condition_1
    or long_condition_2):
    do_some_function()

      

This code, in turn, breaks down E129 visually indented line with same indent as next logical line

into PEP8. However, the second line must be indented exactly four spaces, as it would otherwise break E128 or E127 for clipped or notched lines.

How should the above be formatted so that it confirms the PEP8 standards?

+3


source to share


2 answers


This should work fine



if (long_condition_1 or
       long_condition_2):
    do_some_function()

      

+1


source


The answer to this question has changed over time. Due to the change in position from the PEP8, the W503 is now widely considered against the PEP8.

PEP8 now says that it is okay to split before OR after, but support it locally.



For newer code, Knuth's style is preferred (which I think belongs to a pre-statement hack).

if (
    long_condition_1
    or long_condition_2
    or (
        long_condition_3
        and long_condition4
    )
):
    do_some_function()

      

+1


source







All Articles