For review: PEP 343: Anonymous Block Redux and Generator Enhancements

  • Thread starter Guido van Rossum
  • Start date
R

Roy Smith

Nicolas Fleury said:
It's important to note that nobody is against the PEP syntax. We are
only talking about adding things to it

In think the above is a contradiction in terms.
 
S

Steven Bethard

Nicolas said:
Since the current syntax would be there, the no-indentation syntax can
be explained in terms of the indentation syntax:

"""
To avoid over-indentation, a with-statement can avoid defining a new
indentation block. In that case, the end of the with block is the end
of the current indentation block.

with EXPR as VAR
REST OF BLOCK

is equivalent to

with EXPR as VAR:
BLOCK
"""

What do you think? I fail to see the complexity...

I guess my only real qualm about this is that I think it makes it harder
to see where __exit__() methods are called. When I compare:

def func(arg, baz):
foo = bar(arg)
with x as foo(baz)
x.frobble()
with y as x.bop()
return frabble(x, y)

with:

def func(arg, baz):
foo = bar(arg)
with x as foo(baz):
x.frobble()
with y as x.bop():
return frabble(x, y)

I find it much easier to identify in the second one that __exit__()
methods will be called right before the function returns (after the
return statement). YMMV.

BTW, if you really like the optional-indentation idea, you should post
it to the Wiki page (http://wiki.python.org/moin/WithStatement) --
Guido's been pretty quick to respond to any comments made there, so you
could get some feedback much more useful than I can give you. ;)

STeVe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top