[Python-3000] pep3115 - metaclasses in python 3000

Talin talin at acm.org
Sat Jul 14 06:56:44 CEST 2007


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.

-- Talin


More information about the Python-3000 mailing list