Metaclasses & docstrings in 2.2

Alex Martelli aleax at aleax.it
Wed Jul 24 06:54:33 EDT 2002


<posted & mailed>

Jeremy Bowers wrote:

> Python session you can copy & paste to follow along:
> 
> -----
> 
> class M1:
> "M1's docstring."
> def __init__(cls, name, bases, dict):
> pass
> 
> class A:
> "A's docstring."
> pass
> 
> A.__doc__

There's nothing connecting A and M here, so I can just assume
you forgot something, as well as making __init__ into a noop
(as noticed in a following message).  Anyway...

> (Oh, and this stuff rocks. A three line metaclass, and two lines
> activating it on a couple of base classes, is saving me oodles of typing
> and goodness only knows how many bugs based on forgetting those lines in
> some obscure subclass. I had a hard time understanding the metaclasses
> until I found a need for them, but now it's crystal clear. Thanks, Python
> team, this f'in ROCKS!)

...would you please share your uses for metaclasses?  I can use
all the good examples I learn about -- it's hard to teach people
how to use metaclasses without actual motivation, and the more
real-life examples I can collect and quote, the more likely I
can help people achieve that motivation!


Thanks,

Alex




More information about the Python-list mailing list