[Python-ideas] Parenthesized Compound With Statement
Guido van Rossum
guido at python.org
Wed Jul 3 17:38:04 CEST 2013
Clearly some people have interpreted this dogmatically as "never use
backslashes", so I think we should explicitly update the PEP with more
moderate language and an example.
On Wednesday, July 3, 2013, Barry Warsaw wrote:
> On Jul 02, 2013, at 06:37 PM, Matthew Lefavor wrote:
>
> >As you all know, Python supports a compound "with" statement to avoid the
> >necessity of nesting these statements.
> >
> >Unfortunately, I find that using this feature often leads to exceeding the
> >79-character recommendation set forward by PEP 8.
>
> Yeah, I noticed and brought this up a while ago. I thought I filed a bug
> but
> can't find it. It would have been closed Won't Fix anyway.
>
> As others have pointed out, you can usually rewrite such long
> with-statements
> to conform to the PEP 8 line lengths by e.g. saving the paths in a shorter
> named local variable), using Python 3.3's ExitStack, which is awesome btw,
> or
> just using backslashes. Remember PEP 8 isn't a weapon to be wielded by a
> stern Auntie Tim Peters.
>
> As for relaxing PEP 8, well, I'm not sure what more you'd want it to say.
> It
> currently reads:
>
> The preferred way of wrapping long lines is by using Python's implied
> line continuation inside parentheses, brackets and braces. Long lines
> can be broken over multiple lines by wrapping expressions in
> parentheses. These should be used in preference to using a backslash
> for line continuation.
>
> which seems about right to me. It is preferred to use implied continuation
> over backslashes, but doesn't say "don't use backslashes". They're not
> evil,
> just not preferred, so use them where appropriate and with good judgment.
>
> Cheers,
> -Barry
>
--
--Guido van Rossum (on iPad)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130703/bbb16a56/attachment.html>
More information about the Python-ideas
mailing list