[Python-Dev] On decorators implementation
"Martin v. Löwis"
martin at v.loewis.de
Sun Aug 21 13:18:58 CEST 2005
> I imagine that a method implementation of them inside the type metaclass
> could be better specified by people.
What you ask for is unimplementable. Method objects are created only
when the method is accessed, not (even) when the class is created.
>>> class X:
... def foo(self):
So even though the class has long been defined, inside X's dictionary,
foo is still a function. Only when you *access* x.foo, a method object
is created on the fly:
>>> x.foo is x.foo
Therefore, a decorator function cannot possibly get access to the method
object - it simply doesn't exist.
More information about the Python-Dev