[Python-ideas] A user story concerning things knowing their own names

Guido van Rossum guido at python.org
Fri Mar 18 15:49:09 CET 2011


On Thu, Mar 17, 2011 at 10:12 PM, Ian Bicking <ianb at colorstudy.com> wrote:
> Did you have any opinion on __addtoclass__?  It seemed to me to address most
> of the use cases (even Greg's as far as I understood it).

[Reminder: Ian's proposal is to call attr.__addtoclass__(cls, name)
for all attributes of the class that have the method, at class
construction time.]

You know, somehow I missed that when skimming. :-( It nicely
encapsulates the main reason for having a metaclass in many of these

There's another pattern where all class attributes that have a certain
property are also collected in a per-class datastructure, and at that
point we're back to the custom metaclass; but standardizing on
__addtoclass__ with the proposed signature would be a first step.

We could either have a standard metaclass that does this, or we could
just make it part of 'type' (the default metaclass) and be done with

--Guido van Rossum (python.org/~guido)

More information about the Python-ideas mailing list