Metaclass to make all methods of a class thread-safe
Jeff Shannon
jeff at ccvcorp.com
Mon Sep 27 17:32:09 EDT 2004
Irmen de Jong wrote:
>
> There is one thing though; methods that you're accessing trough the
> class's __dict__ (which is what the meta class is doing, right?)
> are of type <function>, rathar than <instancemethod> which I expected:
>
> >>> class A:
> ... def meth(self): pass
> ...
> >>> type(A.meth)
> <type 'instancemethod'>
> >>> type(A.__dict__['meth'])
> <type 'function'>
> >>>
>
> Why is this?
I don't know for certain, but it occurs to me that the object returned
by A.meth will insert A in front of all other arguments to the method,
while the object returned by A.__dict__['meth'] does not do that. Logic
seems to suggest that the instancemethod type performs this
argument-list-mangling and then passes the results on to the
FunctionType object contained in __dict__ -- that is, instancemethod is
essentially a function wrapper that provides the standard method-call
translations for class instances.
Jeff Shannon
Technician/Programmer
Credit International
More information about the Python-list
mailing list