[Python-3000] Metaclasses in Py3K (original) (raw)
Phillip J. Eby pje at telecommunity.com
Sat Dec 9 02:17:38 CET 2006
- Previous message: [Python-3000] Metaclasses in Py3K
- Next message: [Python-3000] Metaclasses in Py3K
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
At 01:20 PM 12/9/2006 +1300, Greg Ewing wrote:
Talin wrote: > In other words, the > metaclass statement would have a side-effect of replacing the > locals() dict with a mapping object supplied by the metaclass.
metaclass isn't a statement, it's just an attribute that is interpreted in a special way after the class namespace has been populated, by which time it's too late to do what you suggest.
Note that if we simply make locals() set or get attributes on the class instance, assigning to class in the body of the class would actually set the metaclass immediately.
The principal hurdle that would need to be overcome to do this, is that you can't change a builtin type's class currently:
Python 2.5 (r25:51908, Dec 6 2006, 15:13:26) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information.
class X(object): pass ... class Y(type): pass ... X.class = Y Traceback (most recent call last): File "", line 1, in TypeError: class assignment: only for heap types
Fixing this problem in Python 2.6 would be nice, actually, to say nothing of Py3K.
- Previous message: [Python-3000] Metaclasses in Py3K
- Next message: [Python-3000] Metaclasses in Py3K
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]