Another way to spell __metaclass__ ?

Gonçalo Rodrigues op73418 at mail.telepac.pt
Fri Dec 13 10:46:13 EST 2002


On 13 Dec 2002 06:08:42 GMT, bokr at oz.net (Bengt Richter) wrote:

>
>I must confess there is something that bothers me about __metaclass__ as
>an impementation of metaclass functionality. It strikes me more as a
>class transmogrification hook with a debug/trace flavor than a clear expression
>of the relationship between two classes, one of which produces the other
>as an instance.
>
>I.e., to me, the hallmark of a metaclass is that it produces another class when
>instantiated (normally with variations based on conditions or parameters, or why
>do it).

At the risk of having completely missed the point, your gripe with
__metaclass__ is of a purely syntactic nature. A metaclass *is* a class
whose instances are classes themselves, except currently there is simply
no way to attach to a class statement information specifying the
metaclass other than the __metaclass__ thingy.

The same problem happens for example when you want to declare a static
method, you have to use something like

def mystaticmethod(*args, **kwargs):
    <whatever>

mystaticmethod = staticmethod(mystaticmethod)

It would be much better if some kind of pseudo keyword would be
introduced, e.g.

def static mystaticmethod(*args, **kwargs):
    <whatever>

[most interesting stuff snipped]

Unfortunately, as far as I remember, such syntactic sweetening is not
scheduled to happen in the next 2.3.

>
>Regards,
>Bengt Richter

With my best regards,
G. Rodrigues



More information about the Python-list mailing list