Uhm, oops. In that case, this seems to be insanity; having a bunch of incompatible method signatures all in the same inheritance tree makes it rather impossible to sanely invoke all superclass versions, unless all the implementations cooperate. I'm not sure that this is a problem unique to Python, or to super(), but feel free to enlighten me.
Re: One way to do itglyfApril 9 2007, 15:42:12 UTC
I think that this is the only correct solution (james indicates something similar in his age-old post about super()) but it also has a problem: it's not cooperative with classes that don't use this style.
The point of this post is that I am slowly realizing that it is impossible to correctly write mixins in Python. You can't really re-define methods lower in the inheritance hierarchy, you can only overload them, so mixins can pretty much never define __init__. Except, they also can't not define __init__, because then they inherit object's __init__, whose behavior is uncertain and changing.
Your post indicates that Python does provide nice support for inheritance diamonds, as long as the root of the diamond isn't "object".
Re: One way to do itglyfApril 9 2007, 17:01:58 UTC
A "mixin", almost by definition, shouldn't know anything about the properties of the classes it might be mixed in to. It might be necessary, practically speaking, to stipulate that it has to be mixed in to a new-style class or a classic class, since they are subtly incompatible inheritance models, but there should be a "right way" for either one, and I can't see it.
Comments 14
Reply
Reply
Reply
Reply
Here's one way to do it. http://www.fluidinfo.com/terry/index.php/2007/04/07/solve-for-x/
Terry
Reply
The point of this post is that I am slowly realizing that it is impossible to correctly write mixins in Python. You can't really re-define methods lower in the inheritance hierarchy, you can only overload them, so mixins can pretty much never define __init__. Except, they also can't not define __init__, because then they inherit object's __init__, whose behavior is uncertain and changing.
Your post indicates that Python does provide nice support for inheritance diamonds, as long as the root of the diamond isn't "object".
Reply
Reply
Reply
Reply
Reply
Leave a comment