Conflict between how PEP8 E127 is supposed to work and warnings I get

Here below is a screenshot of my code saying it doesn't respect E127 from the PEP 8 rules: enter image description here However, in this link, what is explained as good practice is what I have. Furtheremore, when I use the shortcuts Ctrl + Alt + I (and Alt + Shift + Enter) which are the PyCharm shortcuts to format the line (and the file) according to PEP 8, this (above) is the formatting I obtain (and if I deviate from it, pressing those bring me back to this (above) formatting).

Am I missing something?

EDIT: Another situation when it's not inside parentheses but with an = sign where niko's solution does not apply: https://i.sstatic.net/KIAma.png.

Upvotes: 3

Views: 491

Answers (1)

niko
niko

Reputation: 5281

Idk about your specific question, but personally, the way I indent is as follows

def foo(
    x: int,
    y: int = 1
) -> int:
    res = bar(
        x=x,
        y=y,
        some_very_long_arg="some_very_long_arg"
    )
    return res

PyCharm never complained about that style (I don't think it is against any PEP but I might be wrong).

It feels easier to read when there are many and/or long parameters inside of functions (calls).

A somewhat in the middle approach would be something like this

def foo(
    x: int, y: int = 1
) -> int:
    res = bar(
        x=x, y=y,
        some_very_long_arg="some_very_long_arg"
    )
    return res

Edit

Long strings

string = "very long " \
         "string"
# or
other_string = "string"
string = "very long " + \
         other_string + "!"

Upvotes: 2

Related Questions