On Mon, Apr 24, 2006 at 10:53:39AM -0500, Ian Bicking wrote:
> Here's something for the crazy idea bin...
>
> Right now class creation looks like:
>
> class X(base):
> y = 'z'
>
> This gets the things in the () (object), evaluates the body of the class
> in a new scope and captures that scope (namespace), and looks for a
> metaclass using a couple rules. Then it does:
>
> X = metaclass('X', (base,), {'y': 'z'})
>
> What if instead it did:
>
> X = metaclass('X', (base,))
> X.y = 'z'
This would make overriding __new__ in a metaclass useless because
if you are defining __new__ instead of __init__ you presumably want
to return different things depending on the content of the namespace.
> ? X could keep track of order if it wanted. Or not. There would be no
> conflict between metaclasses paying special attention to the constructor
> namespace, and later attribute setting on the same class (most
> metaprogramming techniques with metaclasses choose one or the other).
I've been working on a dict-alike that is used just for namespaces
(py3k list[1]). I'm hoping it can be faster than a generic dict and
also keep track of the order the keys are defined but faster is the
main goal. Slow going, dicts have _a lot_ of methods to cover.
> It could make rebuilding a class easier (as in reload). If
> metaclass('X', (bases,)) returned the already-existant X class,
> attributes will get folded in. (There's still problems there, but maybe
> this helps a little.)
Can't you do this already?
-Jack
[1] "Specializing the dicts in __dict__"
http://article.gmane.org/gmane.comp.python.python-3000.devel/641/
_______________________________________________
Python-3000 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe:
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com