Re: Functions that raise exceptions.

2008-06-25 Thread Duncan Booth
Alex G <[EMAIL PROTECTED]> wrote: > class classA(object): > @decorator('argument') > def some_method(self): > print "An exception should be raised when I'm called, but not > when I'm defined" > > Will result in an exception on definition. Well, yes it would. That's because what y

Re: Functions that raise exceptions.

2008-06-25 Thread Alex G
I'm sorry about the typos, but that doesn't seem to be what the issue is (I typed it into the textbox rather carelessly, I apologize :-( ). It seems to be an issue with passing the decorator an argument: Given: def decorator(arg): def raise_exception(fn): raise Exception return ra

Re: Functions that raise exceptions.

2008-06-25 Thread Duncan Booth
Alex G <[EMAIL PROTECTED]> wrote: > Does anyone know how I would go about conditionally raising an > exception in a decorator (or any returned function for that matter)? > For example: > > def decorator(arg): > def raise_exception(fn): > raise Exception > return raise_exception >

Re: Functions that raise exceptions.

2008-06-25 Thread Alex G
whoops! The code should be: def decorator(arg):     def raise_exception(fn):       raise Exception   return raise_exception class some_class(object):     @decorator('meaningless string')     def some_method(self):         print "An exception should be raised when I'm called, but not when I'm

Functions that raise exceptions.

2008-06-25 Thread Alex G
Does anyone know how I would go about conditionally raising an exception in a decorator (or any returned function for that matter)? For example: def decorator(arg): def raise_exception(fn): raise Exception return raise_exception class some_class(object): @raise_exception d