[Python-Dev] pep8 reasoning

Barry Warsaw barry at python.org
Sun Apr 27 22:40:39 CEST 2014


On Apr 27, 2014, at 12:34 PM, Chris Barker wrote:

>wow! just looked at that part of the PEP again, and that is a LOT of
>options. Is it impossible to come to any consensus on this? And as it
>happens, my favorite is not in there, though as far as I can tell not
>forbidden:
>
>foo = long_function_name(var_one,
>                                          var_two,
>                                          var_three,
>                                          var_four)

Wow, do you really indent those 42 columns?

This actually is forbidden because you're not using "vertical alignment" when
there is an argument on the first line.  You would have to line up `var_two`
right under `var_one` to be compliant.

>That is, I find that if the argument list is too long for one line, then
>splitting it out to only one argument per line is much more readable to me.

Sure.  The PEP outlines ways to do that.

>This becomes more important with default parameters:
>
>foo = long_function_name(var_one,
>                                          var_two=a_value,
>                                          var_three=some_other_value,
>                                          var_four=(a, tuple, of, values)
>                                          )
>as with more information in each argument, it's a lot more clear where one
>starts and the other begins. And it provides a nice place for comments:
>
>foo = long_function_name(var_one,
>                                          var_two=a_value, # because
>default doesn't frobnicate in this case
>                                          var_three=some_other_value,
>                                          var_four=(a, tuple, of, values)
>                                          )
>
>
>Anyway -- is there a point in trying to standardize this a bit more in
>PEP8, or has that battle long since been fought and conceded ?

The only thing I see wrong (from a PEP 8 standpoint) with your example, is
that your arguments are indented too far to the right.  But e.g. this would be
fine:

foo = long_function_name(var_one,
                         var_two=a_value,
                         var_three=some_other_value,
                         var_four=(a, tuple, of, values)
                         )

Cheers,
-Barry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-dev/attachments/20140427/cdc027fa/attachment.sig>


More information about the Python-Dev mailing list