Hooking exceptions outside of call stack
Warren Stringer
warren at muse.com
Sat Jun 9 12:37:16 EDT 2007
Here is what I would like to do:
#------------------------------------------------------------
a = Tr3() # implements domain specific language
a.b = 1 # this works, Tr3 overrides __getattr__
a.__dict__['b'] = 2 # just so you know that b is local
a[b] = 3 # I want to resolve locally, but get:
Traceback (most recent call last): ...
exec cmd in globals, locals ...
NameError: global name 'b' is not defined
#------------------------------------------------------------
So far, I've tried capturing exceptions in __getattr__, __setitem__, and
__setattr__, with no luck. I do NOT want to put `a[b]=3` inside a
try...except block because I want to enable a command line `>>>a[b]=3`
Is there a way to hook a NameError exception outside of the call stack?
Perhaps, inside Tr3.__init__ ? Is there a way of putting back unhandled
NameError exceptions, so that they unwind the stack normally?
This is intended for production code.
Many thanks!
Warren
More information about the Python-list
mailing list