using metaclass __call__ to replace class instance
Ksenia Marasanova
ksenia.marasanova at gmail.com
Fri Sep 9 09:12:32 EDT 2005
2005/9/9, Peter Otten <__peter__ at web.de>:
> Ksenia Marasanova wrote:
>
> > class BasemethodMeta(type):
> > def__new__(cls,class_name,bases,new_attrs):
> > cls=type.__new__(cls,class_name,bases,new_attrs)
> > new_attrs['__metaclass__'].cls=cls
> > returncls
> >
> > def__call__(self):
> > returnself.cls.get_foo()
>
> Though I'm not sure what you are trying to do, I fear it will get more
> complicated than necessary. But you do get the desired output if
> you change your metaclass to
>
> class BasemethodMeta(type):
> def __call__(cls):
> # the instance of the metaclass already is a class
> # so you can drop the double indirection
> return cls.get_foo()
>
> Peter
>
Man.. that's easy. Thanks a lot, Peter.
--
Ksenia
More information about the Python-list
mailing list