oop - Idiomatic multiple inheritance with python Abstract Base Classes -
in simplest terms want tuple 1 or 2 additional methods. __new__ or __init__ not going modified.
i create abstract base class subclass of collections.abc.sequence. want use tuple subclass. class diagram like:
collections.abc.sequence / \ / \ / \ myabc tuple \ / \ / \ / myclass reasons:
myabcdefines custom interfaces. there third parties not forced subclassmyclass.tupleneeded performance , implemented methods.
questions:
- is idiomatic way write
class myclass(myabc, tuple)or should play registers? - are there other obvious problems missing?
- will space , performance benefits of
tuplelost because of subclassing?
is idiomatic way write class myclass(myabc, tuple) or should play registers?
it looks me quite idiomatic way of doing this. called "inheritance diamond".
__init__methodmyclassthis.are there other obvious problems missing?
well, depends on aspects not quite specified in question, want do? how doing it? how usage pattern of new subclass? how general/specific new methods have in new class? there more efficient/cleaner/readable/easier/whatever way of doing without creating subclass? , if yes, still worth doing, if gain more flexibility/readability , so?
as general rule, it's not ok, desirable create subclasses if use enough and/or enable solve problem more without drastic/highly undesirable collateral effects.
will space , performance benefits of tuple lost because of subclassing?
that's tricky question. again, depending on doing , how design subclass etc..., possibly. remember, example, tuples immutable type , property has performance advantages on mutable types. so, if e.g. somehow modify property, represent loss, compared original tuple. i'm not quite sure how python see subclass of tuple. mean, don't know if python still 'blindly believe' class immutable , still behave tuple. , if not, how bad in specific case. immutable/mutable issue example, other more relevant issues might exist, couldn't sure... maybe small-scale test measure performance.
considering of these aspects (by guido himself) idea.
i hope helps!
Comments
Post a Comment