[Python-Dev] Re: anonymous blocks

Reinhold Birkenfeld reinhold-birkenfeld-nospam at wolke7.net
Tue Apr 26 14:49:41 CEST 2005


Guido van Rossum wrote:
> [Greg Ewing]
>> I like the general shape of this, but I have one or two
>> reservations about the details.
> 
> That summarizes the feedback so far pretty well. I think we're on to
> something. And I'm not too proud to say that Ruby has led the way here
> to some extent (even if Python's implementation would be fundamentally
> different, since it's based on generators, which has some different
> possibilities and precludes some Ruby patterns).

Five random thoughts:

1. So if break and continue are allowed in with statements only when there
   is an enclosing loop, it would be a inconsistency; consider

     for item in seq:
        with gen():
            continue

   when the generator gen catches the ContinueFlow and does with it what it wants.
   It is then slightly unfair not to allow

     with x:
         continue

   Anyway, I would consider both counterintuitive. So what about making ReturnFlow,
   BreakFlow and ContinueFlow "private" exceptions that cannot be caught in user code
   and instead introducing a new statement that allows passing data to the generator?

2. In process of handling this, would it be reasonable to (re)introduce a combined
   try-except-finally statement with defined syntax (all except before finally) and
   behavior (finally is always executed)?

5. What about the intended usage of 'with' as in Visual B.. NO, NO, NOT THE WHIP!

   (not that you couldn't emulate this with a clever "generator":
      def short(x):
          yield x

      with short(my.long["object"]reference()) as _:
          _.spam = _.ham = _.eggs()

yours,
Reinhold

-- 
Mail address is perfectly valid!



More information about the Python-Dev mailing list