When were metaclasses added? (was Re: For review: PEP 308 - If-then-else expression)
Just
just at xs4all.nl
Mon Feb 10 18:40:20 CET 2003
In article <b28l61$7bg$1 at panix2.panix.com>, aahz at pythoncraft.com (Aahz)
wrote:
> In article <7h33cmwyxea.fsf at pc150.maths.bris.ac.uk>,
> Michael Hudson <mwh at python.net> wrote:
> >aahz at pythoncraft.com (Aahz) writes:
> >>
> >> What was implicit in mentioning frequency, I think, is that the
> >> actual metric is frequency times power. Metaclasses are very, very
> >> powerful, so even a low frequency gives them many "feature points".
> >> Also, metaclasses came essentially for free with new-style classes,
> >> which have many other reasons for existing.
> >
> >Metaclasses were also already there, let's not forget.
>
> At the very most, that's two-thirds true. It was essentially impossible
> to use them from Python without loading a special module, and even then
> there were many more restrictions on its use. The *idea* of metaclasses
> was certainly there (and essential/intrinsic to Python's object model),
> but I think it's fair to say that metaclasses in Python had little more
> existence than subclassing of builtin types (which you could
> theoretically do from C prior to 2.2).
The "Don Beaudry hook" did not require a special module. It was still a
pain to work with, but it was there. Here's a 1.5.2 session:
Python 1.5.42+ (#43, Oct 9 2000, 11:42:55) [CW PPC w/GUSI w/MSL]
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> class MetaClass:
... def __init__(self, name, bases, methoddict):
... print "making new class named", name
...
>>> AFakeClass = MetaClass("AFakeClass", (), {})
making new class named AFakeClass
>>> class Foo(AFakeClass): pass
...
making new class named Foo
>>> Foo
<__main__.MetaClass instance at 8244060>
>>> Foo.__class__
<class __main__.MetaClass at 8244ba0>
>>>
Just
More information about the Python-list
mailing list