Problems with PEP8 indentation rules

Asked

Viewed 225 times

2

I’m using the autopep8 extension in sublime text 3 and it suggests to me that the following line looks like this:

self.buttons = [Button(self.fonts["alfa_slab_one_regular_40"], "JOGAR",
                       midtop=[self.screen_rect.centerx, 250 + 0 * 80])
                for index, button in ["jogar torneio ranking \
                opções".split()]]

So it is correct according to PEP8 or it should be so:

self.buttons = [Button(self.fonts["alfa_slab_one_regular_40"], "JOGAR",
                midtop=[self.screen_rect.centerx, 250 + 0 * 80])
                for index, button in ["jogar torneio ranking \
                opções".split()]]
  • I have asked a question and answer that may help with similar questions in the future: https://answall.com/q/260186/3635

1 answer

0

The conventions on Hanging indentation of PEP 8 say that the next line should follow the first parameter, not the function itself. See:

# faça
foo = long_function_name(var_one, var_two,
                         var_three, var_four)

# não faça
foo = long_function_name(var_one, var_two,
    var_three, var_four)

See that var_three must go below var_one and not of long_function_name.

This should solve in your case. In indentation section of PEP 8 there are some other guidelines and exceptions.

Thus, in your case the correct, according to PEP 8, would be the first way:

self.buttons = [Button(self.fonts["alfa_slab_one_regular_40"], "JOGAR",
                       midtop=[self.screen_rect.centerx, 250 + 0 * 80])
                for index, button in ["jogar torneio ranking \
                opções".split()]]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.