Feb-14-2019, 09:24 AM
(This post was last modified: Feb-14-2019, 09:37 AM by denis_beurive.)
@ichabod801
Yes, good point. If two classes have a parent in common, you cannot use the list "__base__".
I was thinking that I could include within the parent class a flag that indicates whether class has been initialised or not : thus the parent class will be initialised only once. However, I think that this would be a bad practice. Indeed, this technique is tightly bound to a specific Python implementation. If Python changes the way it treats multiple inheritance in the future, then this technique will produce errors.
Yes. I've seen.
However, the function "super" have multiple signatures.
It seems that we can call "super()" on the class other than the current one (that is "__class__").
For example, we can call super on a parent class, from a child class. But I cannot see any good reason to do that.
Yes, good point. If two classes have a parent in common, you cannot use the list "__base__".
I was thinking that I could include within the parent class a flag that indicates whether class has been initialised or not : thus the parent class will be initialised only once. However, I think that this would be a bad practice. Indeed, this technique is tightly bound to a specific Python implementation. If Python changes the way it treats multiple inheritance in the future, then this technique will produce errors.
(Feb-13-2019, 05:51 PM)ichabod801 Wrote: snippsat
Yes. I've seen.
However, the function "super" have multiple signatures.
Quote: super() -> same as super(__class__, <first argument>)
super(type) -> unbound super object
super(type, obj) -> bound super object; requires isinstance(obj, type)
super(type, type2) -> bound super object; requires issubclass(type2, type)
It seems that we can call "super()" on the class other than the current one (that is "__class__").
For example, we can call super on a parent class, from a child class. But I cannot see any good reason to do that.