[Python-ideas] A (meta)class algebra
Antony Lee
antony.lee at berkeley.edu
Thu Feb 12 21:22:55 CET 2015
Create the required inheriting metaclass on the fly:
def multi_meta(*clss):
"""A helper for inheriting from classes with different metaclasses.
Usage:
class C(multi_meta(A, B)):
"A class inheriting from classes A, B with different
metaclasses."
"""
mcss = tuple(type(cls) for cls in clss)
mcs = type(
"Meta[{}]".format(", ".join(mcs.__name__ for mcs in mcss)), mcss,
{})
return mcs("[{}]".format(", ".join(cls.__name__ for cls in clss)),
clss, {})
I have the same use-case as you, i.e. mixing custom metaclasses with
QObjects.
2015-02-12 10:36 GMT-08:00 Ethan Furman <ethan at stoneleaf.us>:
> On 02/12/2015 05:42 AM, Martin Teichmann wrote:
>
> > class MetaQRegistrar(MetaRegistrar, type(QObject)):
> > pass
> >
> > but then you always have to write something like
> >
> > class Spam(Registrar, QObject, metaclass=MetaQRegistrar):
> > pass
>
> or:
>
> class RQObject(metaclass=MetaQRegistrar):
> pass
>
> class Spam(RQObject):
> pass
>
> --
> ~Ethan~
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150212/ef33d8da/attachment.html>
More information about the Python-ideas
mailing list