Hooking exceptions outside of call stack

Warren Stringer warren at muse.com
Sat Jun 9 20:51:18 EDT 2007


Josiah Carlson wrote:
>  >>> foo = type(foo)(foo.func_code, d, foo.func_name, foo.func_defaults,
> foo.func_closure)

Wow! I've never seen that, before. Is there documentation for `type(n)(...)`
somewhere? I did find a very useful "Decorator for Binding Constants, by
Raymond Hettinger", that uses this technique.

The calls are made from embedded classes that are constructed on the fly:

  class a(object): ...
    class b(object): ...
       class c(object): ...

for `a.b[c]=1`, a.__getattr__('b') is called but 'c' need to be resolved as
an object before a.b.__getitem__(c) is called. Could a.b.__init__ set
globals so that 'c' gets resolved? Is this global namespace the same as the
`globals()` namespace? 

Cheers,

\~/




More information about the Python-list mailing list