[Python-Dev] New metaclass pattern (Was Re: Simulating Class (was Re: Does Python have Class methods))
James_Althoff at i2.com
James_Althoff at i2.com
Wed May 23 16:14:08 EDT 2001
Guido wrote:
<snip>
>Yes. You should be able to subclass an existing metaclass!
>Fortunately, in the descr-branch code in CVS, this is possible. I
>haven't explored it much yet, but it should be possible to do things
>like:
>
>Integer = type(0)
>Class = Integer.__class__ # same as type(Integer)
>
>class MyClass(Class):
> ...
>
>MyObject = MyClass("MyObject", (), {})
>
>myInstance = MyObject()
>
>Here MyClass declares a metaclass, and MyObject is a regular class
>that uses MyClass for its metaclass. Then, myInstance is an instance
>of MyObject.
<snip>
>--Guido van Rossum (home page: http://www.python.org/~guido/)
Nice! Can you then do:
import new
def myObjectMethod(self): pass
MyObject.myObjectMethod =
new.instancemethod(myObjectMethod,MyObject,MyClass)
MyObject.myObjectMethod()
(as with "non-class-object" instances)???
Any news on the "conflicting methods" issue (e.g., (instance|class).
__repr__)?
Jim
More information about the Python-list
mailing list