metaclass - Python: Metaclasses all the way down -
I have a mysterious question that includes Python metaLess I create a Python package for web-server-side code I've been using arbitrary python classes through a client-side proxy to make it easy to use. My proxy-generating code requires a list of all Python classes, which I want to include in my API. To create this list, I am using the __ metaClass __
special feature to put a hook in the class-creation process. Specifically, all classes in the "published" API set to enter information about a particular base class, Python Direct PR
, which is __ metaclass __
Has been building the class.
So far so good. Where it gets complicated, it is to get me own Python Direct PR
in the succession from a third-party class ( enthought.traits.api.HasTraits
) itself Want to This third-party class uses also a __ metaclass __
.
What is the correct way of managing two metaquals? Should my Metaclass be a subclass of Intetech Metaclass? Or should I just add the metathesal of Antiteite within the __New __
method of Metallus, the way I will be back? Or are there some other mysterious lights to use in this particular situation?
Should my metacles be a subclass of inhite metaclaces?
I believe that in fact your only option is if the MetaCalass of the derived class is not the subclass of the MetaClass of all its bases, when you try to create the derived class , Then Python will put a type error. Therefore, your Metaclass for PythonDirectPublic
Code> with class should appear like DerivedMetaClass (BaseMetaClass): def __new __ (cls, name, bases, dct): # your custom memory Allocation here, if any # now return the base metables to its memory allocation contents, Besameta class.__ new__ (CLS, names, chairs, DCT) def __init __ (cls, name, bases, dct): #, me Feel, where your inventory building material takes place # Now the base metacolus doing its initial accessories (DerivedMetaClass, cls) If you do not have access to the definition of the meta class of the base class of your third party, then you
BaseMetaClass >
enthought.traits.api.HasTraits .__ metaclass __
. It's literal, but it will work.
Comments
Post a Comment