[Python-Dev] A grammatical oddity: trailing commas in argument lists -- continuation

Jan Kaliszewski zuo at chopin.edu.pl
Mon Dec 13 15:18:34 CET 2010


Nick Coghlan dixit (2010-12-13, 23:25):

> Function arguments are not lists. Even when separated onto multiple
> lines, the closing "):" should remain on the final line with other
> content.

Not necessarily, IMHO.

1.
What about my example with '-> xxx' return-value annotation? (especially
when that annotation is a long expression)

2.
There are two argument-list-formatting idioms I apply -- depending on
which is more suitable in a particular case:

a) 
when argument specs/expressions are not very long and rather if their
number is not very big:

    def function(argument_spec1, argument_spec2, argument_spec3,
                 argument_spec4, argument_spec5, argument_spec6):

    function_call(expression1, expression2, expression3,
                  expression4, expression5, expression6)

b)
for long argument lists and/or argument specs/expressions (e.g. when
default values or argument annotations are defined as long expressions):

    def function(
        long_argument_spec1,
        long_argument_spec2,
        long_argument_spec3,
        long_argument_spec4,
        long_argument_spec5,
        long_argument_spec6,
    ):

    function_call(
        long_expression1,
        long_expression2,
        long_expression3,
        long_expression4,
        long_expression5,
        long_expression6,
    )

Note that option 'b' is more convenient for refactorization, diffs etc.

Regards,
*j



More information about the Python-Dev mailing list