[Python-Dev] Multiline with statement line continuation
steve at pearwood.info
Sat Aug 16 05:08:48 CEST 2014
On Fri, Aug 15, 2014 at 02:08:42PM -0700, Ethan Furman wrote:
> On 08/13/2014 10:32 AM, Steven D'Aprano wrote:
> >(2) Also note that *this is already the case*, since tuples are made by
> >the commas, not the parentheses. E.g. this succeeds:
> ># Not a tuple, actually two context managers.
> >with open("/tmp/foo"), open("/tmp/bar", "w"):
> > pass
> Thanks for proving my point! A comma, and yet we did *not* get a tuple
> from it.
Um, sorry, I don't quite get you. Are you agreeing or disagreeing with
me? I spent half of yesterday reading the static typing thread over on
Python-ideas and it's possible my brain has melted down *wink* but I'm
confused by your response.
Normally when people say "Thanks for proving my point", the implication
is that the person being thanked (in this case me) has inadvertently
undercut their own argument. I don't think I have. I'm suggesting that
the argument *against* the proposal:
"Multi-line with statements should not be allowed, because:
is syntactically a tuple"
is a poor argument (that is, I'm disagreeing with it), since *single*
line parens-free with statements are already syntactically a tuple:
with spam, eggs, cheese: # Commas make a tuple, not parens.
I think the OP's suggestion is a sound one, and while Nick's point that
bulky with-statements *may* be a sign that some re-factoring is needed,
there are many things that are a sign that re-factoring is needed and
I don't think this particular one warrents rejecting what is otherwise
an obvious and clear way of using multiple context managers.
More information about the Python-Dev