[Python-3000] Metaclass syntax?
Jonathan LaCour
jonathan-lists at cleverdevil.org
Tue May 2 17:24:15 CEST 2006
Guido van Rossum wrote:
> This has usually been solved by creating a non-meta class whose only
> purpose is to introduce the new metaclass. You'd write
>
> class TheLarch(KindsOfTrees, deciduous): ...
>
> and the metaclass would be called KindsOfTreesMeta.
I think many people find this ugly. I have a little helper function
that
I use to make things a little clearer (at least in my eyes). Of course,
these things are always in the eye of the beholder (as evidenced by the
original message).
def of_type(metaclass):
class MetaclassMixin(object):
__metaclass__ = metaclass
return MetaclassMixin
... and then I simply use this on my classes when I define them:
class MyClass(of_type(SomeMetaclass)):
...
I find this to be fairly useful, and simple.
--
Jonathan LaCour
http://cleverdevil.org
More information about the Python-3000
mailing list