Hooking dir() September 07, 2006
While working with proxy objects I found introspection quite hard, as the mechanism of dir()
just looks at the object’s __dict__
(with some exceptions), and there’s no way to customize
this introspection. But do not fear, hacking skillz are near! After reading into the machinery
of dir()
, I found a nifty solution to this problem.
Note: since python 2.6, __dir__
is a special method that’s invoked by dir()
, if it exists,
so there’s no reason to use this code. Use only on earlier versions of python.