[Python-checkins] peps: Add rules for indenting continuation lines.

Barry Warsaw barry at python.org
Thu Jun 2 20:19:00 CEST 2011


On Jun 02, 2011, at 08:09 PM, guido.van.rossum wrote:

>+    Continuation lines should align wrapped elements either vertically using 
>+    Python's implicit line joining inside parentheses, brackets and braces,
>+    or using a hanging indent of double your code indention, in which case 
>+    there should be no argument on the first line. For example:
>+
>+    Yes:  # Aligned with opening delimiter
>+          foo = long_function_name(var_one, var_two,
>+                                   var_three, var_four)
>+
>+          # Double code indention for hanging indent; nothing on first line
>+          foo = long_function_name(
>+                  var_one, var_two, var_three,
>+                  var_four)
>+
>+    No:   # Stuff on first line forbidden
>+          foo = long_function_name(var_one, var_two,
>+              var_three, var_four)
>+
>+          # 2-space hanging indent forbidden
>+          foo = long_function_name(
>+            var_one, var_two, var_three,
>+            var_four) 

As I mentioned to Guido, I'm not sure where the double-indent recommendation
comes from, but it's entirely possible I missed that discussion.  I agree with
the recommendations, but think a single-indentation level looks fine.  E.g.

        return dict(
            fqdn_listname=member.mailing_list,
            address=member.address.email,
            role=role,
            user=path_to('users/{0}'.format(member.user.user_id)),
            self_link=path_to('members/{0}'.format(member.member_id)),
            )

or

    return b'{0}://{1}:{2}/{3}/{4}'.format(
        ('https' if as_boolean(config.webservice.use_https) else 'http'),
        config.webservice.hostname,
        config.webservice.port,
        config.webservice.api_version,
        (resource[1:] if resource.startswith('/') else resource),
        )

-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-checkins/attachments/20110602/cd8f1ebe/attachment-0001.pgp>


More information about the Python-checkins mailing list