[Python-3000] pep3115 - metaclasses in python 3000 (original) (raw)
Guido van Rossum guido at python.org
Tue Jul 17 01:58:36 CEST 2007
- Previous message: [Python-3000] pep3115 - metaclasses in python 3000
- Next message: [Python-3000] pep3115 - metaclasses in python 3000
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 7/13/07, Talin <talin at acm.org> wrote:
Thomas Heller wrote: > playing a little with py3k... > > pep3115 mentions that "prepare returns a dictionary-like object > which is used to store the class member definitions during evaluation > of the class body." > > It does not mention whether this dict-like object is used afterwards > as the class-dictionary of the created class or not (when the new > method of the metaclass is called).
The intention is that it's up to the metaclass to decide. I suspect that most metaclasses won't want to use the dict-like object as the class dict, for two reasons: 1) The behavior of assigning to the class dict after class creation is likely to be different than the behavior of assignment during class creation. In particular, a typical 'dict-like' object is likely to be slower than a dict (it has more work to do, after all), and you don't want that slowness around once your class is finished initializing. 2) A 'dict-like' object doesn't have to support all of the methods of a real dict, wherease a class dict does. So your dict-like wrapper can be relatively simple.
The object returned by prepare() actually is incorporated into the class object, unless the metaclass' new() passes something else to type.new(). However this isn't obvious when you ask for the class' dict attribute: you always get a dict proxy.
-- --Guido van Rossum (home page: http://www.python.org/~guido/)
- Previous message: [Python-3000] pep3115 - metaclasses in python 3000
- Next message: [Python-3000] pep3115 - metaclasses in python 3000
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]