Inheritance in Python Such That All Base Functions Are Called -
Actually, what I have to do is:
class B: def fn (A, B): Pass C = C () CFN ()
P> and output AB
How do I apply the Expand Inherit Decorator?
It is not a job for decorators. You want to completely change the general behavior of a class, so it is actually a job for MetaClass.
import type class callAll (type): "" MetaClass which adds methods for all calls Superclass implementation "" def __new __ (meta, clns, chairs, ethers): # # superselles funcs = {} base Collect a list of the assigned tasks for the base: For the name, the wars in the Wall (base) .iteritems (): If the type is (vaal) type. Function type: If the funcs name: funcs [name] .append Val) else: funcs [name] = [val] ## We now have all the methods, so each of them Funcs: def caller (self, * args, ** kwargs) for the name: funcs [name]: func (self, * args, ** kwargs) attrs [name] = caller in all the baseclass implementation for func Class "B" Class A: DF FN (Self): Print 'A' Class C "" Call "return type .__ new____ (ADA, CLSN, Chairs, ethers) Class B: DF FN (SIF): Print 'B' Class A: (A, B, Object): __ MetaClass __ = call cc = c () C.fn ()
Comments
Post a Comment