Is it dangeous when using custom metaclass?

jfong at ms4.hinet.net jfong at ms4.hinet.net
Mon Oct 15 21:16:50 EDT 2018


class StructureMeta(type):
    def __init__(self, clsname, bases, clsdict):
        offset = 0
        ...
        ...
        setattr(self, 'struct_size', offset)

class Structure(metaclass=StructureMeta):
    ...
    ...

class PolyHeader(Structure):
    ...
    ...

As my understanding, the metaclass's __init__ was called when a class was created. In the above example, both the Structure and PolyHeader called it. My question is: because the PolyHeader inherited Structure, is it reasonable for PolyHeader to call this __init__ again? Will it cause any possible trouble?

--Jach



More information about the Python-list mailing list