Problems with indentation rules PEP8

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's correct according to PEP8 or it should look 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()]]
    
asked by anonymous 02.12.2017 / 14:05

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

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

So, in your case the correct one, according to PEP 8, would be the first form:

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()]]
    
02.12.2017 / 14:39