I know (now) that python lets you have an interceptor method that
gets called before a named method is called even. Does it allow this
method to be generated by the generic fallback method?
In Perl terms, assume we have a method PRE that gets called before
any method in a class is called, and AUTOLOAD which is called if you
call a method on a class and that method doesn't exist. Does AUTOLOAD
have to get called to check for PRE if PRE doesn't exist in a class?
--
Dan
--------------------------------------"it's like this"-------------------
Dan Sugalski even samurai
d...@sidhe.org have teddy bears and even
teddy bears get drunk
Python doesn't really have "interceptor methods". In fact, there
aren't any magic methods that are called specifically on method
calling -- only attribute access (well, except for __call__, which
happens when you do obj(), but that's a separate step in the process).
__getattribute__(self, name) --> Always called on attribute access.
__getattr__(self, name) --> Called after looking up the attribute
fails by regular means.
__get__(self, obj, type=None) --> Called on an object when that object
is accessed as an attribute of
another object. f34r this. :-)
Any of which, of course, can return methods. :-) btw, remember how
Python creates `bound methods' when you access a method through an
instance? It's implemented with (the C equivalent of) __get__ (As of
Python 2.2). More information related to that (and other useful
information in general) is here:
http://www.python.org/2.2.2/descrintro.html.
Btw, these all have `set' and `del' friends, but they don't always
perfectly match up with the `get's... I'll get back to you on that.
--
Twisted | Christopher Armstrong: International Man of Twistery
Radix | Release Manager, Twisted Project
---------+ http://twistedmatrix.com/users/radix.twistd/
In Perl 5, AUTOLOAD is called for destructors :
$ perl -wle 'sub AUTOLOAD{print $AUTOLOAD};bless{}'
main::DESTROY
While I think this is annoying in most cases, I imagine this may be
useful. And adding an empty destructor to a class is not a huge effort.
The situation is similar for a PRE method. If it's not defined, there's
no error ; if it's not defined but if AUTOLOAD exists, AUTOLOADing is
tried. (I imagine that if AUTOLOAD gracefully refuses to create the PRE
method, no further attempt will be made.)