[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-dev
Subject:    Re: [Python-Dev] PEP 310 and exceptions
From:       holger krekel <hpk () trillke ! net>
Date:       2005-04-23 8:10:41
Message-ID: 20050423081041.GA30548 () solar ! trillke ! net
[Download RAW message or body]

On Fri, Apr 22, 2005 at 19:03 -0700, Josiah Carlson wrote:
> hpk@trillke.net (holger krekel) wrote:
> > basically translates to: 
> > 
> >     if hasattr(x, '__enter__'): 
> >         x.__enter__() 
> >     try: 
> >         ... 
> >     except: 
> >         if hasattr(x, '__except__'): x.__except__(...) 
> >         else: x.__exit__()
> >     else: 
> >         x.__exit__()
> 
> Nope...
> 
> >>> def foo():
> ...     try:
> ...         print 1
> ...         return
> ...     except:
> ...         print 2
> ...     else:
> ...         print 3
> ...
> >>> foo()
> 1
> >>> 

doh! of course, you are right.  So it indeeds better translates 
to a nested try-finally/try-except when transformed to python code. 
Nick Coghlan points at the correct ideas below in this thread. 

At the time i was implementing things by modifying ceval.c 
rather than by just a compiling addition, i have to admit. 

cheers, 

    holger
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/python-dev%40progressive-comp.com
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic