RELEASED Python 2.4, alpha 2

David Eppstein eppstein at ics.uci.edu
Thu Aug 5 14:45:15 EDT 2004


In article <Pine.LNX.4.44.0408051353150.11711-100000 at ccc6.wpi.edu>,
 Christopher T King <squirrel at WPI.EDU> wrote:

> On Thu, 5 Aug 2004, David Eppstein wrote:
> 
> > If this is an actual possibility, there's nothing preventing you from 
> > wrapping a decorated def inside a try-except block.
> 
> And then being forced to duplicate the function definition.  The way
> around this is, of course, to decorate manually, but then your decorators
> are segmented (some at the top of the function, some at the bottom).

Let me get this straight: you're envisioning a situation in which you 
want to decorate a function, the decorator might fail, and if it does 
you want to do something else (perhaps including not decorating it at 
all), but with the same function body?

If so, that's easy:

def my_robust_decorator(func):
    try:
        return decorator_that_might_fail(func)
    except:
        return something_else

@my_robust_decorator
def func(args...):
   ....


So what's the problem?

-- 
David Eppstein
Computer Science Dept., Univ. of California, Irvine
http://www.ics.uci.edu/~eppstein/



More information about the Python-list mailing list