[Python-ideas] with-statement syntactic quirk

Antoine Pitrou solipsis at pitrou.net
Thu Nov 1 11:48:06 CET 2012


On Thu, 1 Nov 2012 07:33:16 +0100
Barry Warsaw <barry at python.org> wrote:
> On Oct 31, 2012, at 06:47 PM, Raymond Hettinger wrote:
> 
> >I would rather live a bashslash than have yet another change to the grammar
> >or have context-manager semantics added to tuples.
> 
> Yeesh.  Despite the wink I guess people took me seriously about the tuples
> thing.  I mean, really, c'mon! :)
> 
> >ISTM that this isn't a problem worth solving.  
> 
> There are certainly other ways to refactor away the long lines.  It's an odd
> corner of syntactic quirkery that really only came about as I began removing
> nested() calls, and nested context managers are already probably pretty rare.
> It doesn't bother me that it's not worth "fixing" but I'm glad the discussion
> is now captured for eternity in a mail archive.

Uh, what people seem to miss is that it's not only about nested context
managers. It can happen with a single context manager:

with (some_context_manager(many_arguments...)
      as my_variable):
    ...

# SyntaxError!


Regards

Antoine.





More information about the Python-ideas mailing list