metaclasses and setting __class__
Gordon McMillan
gmcm at hypernet.com
Wed Jun 2 18:05:01 EDT 1999
scott cotton writes:
> Last night i was playing with meta classes, and found out
> that we are not able to assign an instance's __class__
> attribute to a metaclass instance. was just wondering if
> this is probably always going to be the case, or if there
> are any plans to make .__class__ assignable to such beasts.
It wouldn't do any good. By the time you have an instance, it's too
late to add metaclass behaviors. All the magic happens at the time
the "class MyClass(MyMetaClassInstance):" is encountered. At this
point, MyMetaClassInstance can do all kinds of evil things to the way
MyClass works.
Assigning to an instance's __class__ will alter the instance's
behavior and appearance, but not to the same extent that using a
metaclass will.
It's-like-changing-your-name-to-"Crazy"
-instead-of-being-born-that-way-ly y'rs
- Gordon
More information about the Python-list
mailing list