osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Is it dangeous when using custom metaclass?


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