Re: Multiple inheritance, super() and changing signature

2016-06-04 Thread Nagy László Zsolt
> > Things to know about super: > Part 1 http://www.artima.com/weblogs/viewpost.jsp?thread=236275 > Part 2 http://www.artima.com/weblogs/viewpost.jsp?thread=236278 > Part 3 http://www.artima.com/weblogs/viewpost.jsp?thread=237121 > > The wonders of super: >

Re: Multiple inheritance, super() and changing signature

2016-06-04 Thread Steven D'Aprano
On Sat, 4 Jun 2016 09:52 pm, Gregory Ewing wrote: > Ian Kelly wrote: >> >> It can't belong to a subclass; the MRI guarantees that. But it's not >> necessarily a superclass either. > > Er, yes, what I really meant to say was that it could > be a class that got introduced into the MRO as a result

Re: Multiple inheritance, super() and changing signature

2016-06-04 Thread Gregory Ewing
Steven D'Aprano wrote: On Sat, 4 Jun 2016 11:06 am, Gregory Ewing wrote: there is no need to use super. Except then you are precluding others from integrating your classes into their class hierarchies. And if you *do* use super, you're precluding integrating them into other hierarchies

Re: Multiple inheritance, super() and changing signature

2016-06-04 Thread Gregory Ewing
Ian Kelly wrote: It can't belong to a subclass; the MRI guarantees that. But it's not necessarily a superclass either. Er, yes, what I really meant to say was that it could be a class that got introduced into the MRO as a result of someone else subclassing your class. So when you make a

Re: Multiple inheritance, super() and changing signature

2016-06-03 Thread Ian Kelly
On Jun 3, 2016 7:12 PM, "Gregory Ewing" wrote: > > 4. It must not matter what order the methods in a super > chain are called. This is because you cannot predict > which method a given super call will invoke. It could > belong to a subclass of the class making the

Re: Multiple inheritance, super() and changing signature

2016-06-03 Thread Steven D'Aprano
On Sat, 4 Jun 2016 11:06 am, Gregory Ewing wrote: > Nagy László Zsolt wrote: >> I do not use diamond shapes in my hierarchy, I guess that does not >> affect me. I may be wrong. > > If there are no diamonds, In Python 3, or Python 2 with new-style classes, there are ALWAYS diamonds when you use

Re: Multiple inheritance, super() and changing signature

2016-06-03 Thread Gregory Ewing
Ben Finney wrote: With classes all inheriting ultimately from ‘object’ (as all Python 3 classes do, and as all current Python 2 classes should), mutliple inheritance inevitably places your classes in a diamond inheritance pattern. That's usually harmless, though, because object provides very

Re: Multiple inheritance, super() and changing signature

2016-06-03 Thread Gregory Ewing
Nagy László Zsolt wrote: I do not use diamond shapes in my hierarchy, I guess that does not affect me. I may be wrong. If there are no diamonds, there is no need to use super. Explicit inherited method calls, done correctly, will work fine. The only downside is that if your inheritance

Re: Multiple inheritance, super() and changing signature

2016-06-03 Thread Ben Finney
Ian Kelly writes: > Except that since we're discussing design for multiple inheritance, > the positional argument "spam" is inappropriate. All arguments should > be passed by keyword; the DolorSitAmet.__init__ method cannot be > certain that LoremIpsum will be the next

Re: Multiple inheritance, super() and changing signature

2016-06-03 Thread Ian Kelly
On Fri, Jun 3, 2016 at 2:16 PM, Ben Finney wrote: > If you're writing a custom initialiser that handles two additional > parameters, then those parameters should not be present when you call > the super() method's initialiser:: > > # You specified Python 3, which

Re: Multiple inheritance, super() and changing signature

2016-06-03 Thread Ben Finney
Nagy László Zsolt writes: > Fortunately, I can change all of the classes, and extracting the > common parameter into a common base class worked. This is why Liskov's Substitution Principle is good: Thinking of it as a law helps lead to better design. In this case, the

Re: Multiple inheritance, super() and changing signature

2016-06-03 Thread Ben Finney
Nagy László Zsolt writes: > So you are right: the custom __init__ in the BootstrapDesktop class is > not really needed, and does not do anything useful in that particular > class. I disagree: setting initial attributes is a normal and useful case for defining a custom

Re: Multiple inheritance, super() and changing signature

2016-06-03 Thread Michael Selik
On Fri, Jun 3, 2016 at 12:01 PM Nagy László Zsolt wrote: > > Is the problem that the attribute or parameter has the same name in > both base classes, but has different meanings in each? > If they had different meanings, a simple rename would solve the problem. > Sometimes

Re: Multiple inheritance, super() and changing signature

2016-06-03 Thread Nagy László Zsolt
Is the problem that the attribute or parameter has the same name in both base classes, but has different meanings in each? If they had different meanings, a simple rename would solve the problem. They have the same meaning. If you can't change the base classes, I've got some other

Re: Multiple inheritance, super() and changing signature

2016-06-03 Thread Michael Selik
On Fri, Jun 3, 2016 at 10:41 AM Ian Kelly wrote: > On Fri, Jun 3, 2016 at 8:06 AM, Nagy László Zsolt > wrote: > > There is still something I don't get: how to create cooperative classes > > when some base classes share some of the parameters? > > Why

Re: Multiple inheritance, super() and changing signature

2016-06-03 Thread Ian Kelly
On Fri, Jun 3, 2016 at 8:06 AM, Nagy László Zsolt wrote: > >>> That's overly strict. As Raymond shows, it is easy to deal with >>> changing method signatures in *cooperative* classes. >> I must watch that for sure. > > All right, I have read this: > >

Re: Multiple inheritance, super() and changing signature

2016-06-03 Thread Nagy László Zsolt
>> That's overly strict. As Raymond shows, it is easy to deal with >> changing method signatures in *cooperative* classes. > I must watch that for sure. All right, I have read this: https://rhettinger.wordpress.com/2011/05/26/super-considered-super/ There is still something I don't get: how

Re: Multiple inheritance, super() and changing signature

2016-06-03 Thread Nagy László Zsolt
>> But I have to initialize some default attributes. > Then the statement “there is NOTHING else here” must be false. Either > the custom ‘__init__’ does something useful, or it doesn't. Well... the custom __init__ method with nothing else just a super() call was expressed there to show the

Re: Multiple inheritance, super() and changing signature

2016-06-03 Thread Steven D'Aprano
On Fri, 3 Jun 2016 07:18 am, Random832 wrote: > On Thu, Jun 2, 2016, at 13:36, Steven D'Aprano wrote: [...] >> But since the constructor/initialiser methods are so closely linked, many >> people are satisfied to speak loosely and refer to "the constructor" as >> either, unless they specifically

Re: Multiple inheritance, super() and changing signature

2016-06-03 Thread Nagy László Zsolt
> Raymond Hettinger gives an excellent presentation where he describes various > problems with MI and gives solutions for them. I think this might be it: > > http://pyvideo.org/video/1094/the-art-of-subclassing-0 This is a much better version from one year later:

Re: Multiple inheritance, super() and changing signature

2016-06-03 Thread Ben Finney
Nagy László Zsolt writes: > > [...] > >> class BootstrapDesktop(BootstrapWidget, BaseDesktop): > >> def __init__(self, appserver, session): > >> # there is NOTHING else here, it just connects bootstrap widget > >> implementation with desktop methods > >>

Re: Multiple inheritance, super() and changing signature

2016-06-03 Thread Nagy László Zsolt
> > In Python 3, that will be automatic and you don't need to worry about it. I'm using Python 3. I'm aware of old style and new style classes in Python 2. > > > [...] >> class BootstrapDesktop(BootstrapWidget, BaseDesktop): >> def __init__(self, appserver, session): >> # there is

Re: Multiple inheritance, super() and changing signature

2016-06-02 Thread Marko Rauhamaa
Random832 : > But from a class-definition perspective, __init__ is the one and only > thing that should be called a constructor. Not arguing agaist that, but from the *user's* perspective, I see the class itself is the constructor function: class C: pass c = C()

Re: Multiple inheritance, super() and changing signature

2016-06-02 Thread Random832
On Thu, Jun 2, 2016, at 13:36, Steven D'Aprano wrote: > On Thu, 2 Jun 2016 06:22 pm, Lawrence D’Oliveiro wrote: > > > On Wednesday, June 1, 2016 at 8:02:14 AM UTC+12, Ben Finney wrote: > >> (Note that ‘__init__’ is not a constructor, because it operates on the > >> *already constructed* instance,

Re: Multiple inheritance, super() and changing signature

2016-06-02 Thread Ian Kelly
On Thu, Jun 2, 2016 at 11:36 AM, Steven D'Aprano wrote: > On Thu, 2 Jun 2016 06:22 pm, Lawrence D’Oliveiro wrote: > >> On Wednesday, June 1, 2016 at 8:02:14 AM UTC+12, Ben Finney wrote: >>> (Note that ‘__init__’ is not a constructor, because it operates on the >>> *already

Re: Multiple inheritance, super() and changing signature

2016-06-02 Thread Steven D'Aprano
On Thu, 2 Jun 2016 06:22 pm, Lawrence D’Oliveiro wrote: > On Wednesday, June 1, 2016 at 8:02:14 AM UTC+12, Ben Finney wrote: >> (Note that ‘__init__’ is not a constructor, because it operates on the >> *already constructed* instance, and does not return anything. > > Believe it or not, that *is*

Re: Multiple inheritance, super() and changing signature

2016-06-02 Thread Michael Selik
On Thu, Jun 2, 2016 at 4:26 AM Lawrence D’Oliveiro wrote: > On Wednesday, June 1, 2016 at 8:02:14 AM UTC+12, Ben Finney wrote: > > (Note that ‘__init__’ is not a constructor, because it operates on the > > *already constructed* instance, and does not return anything. > >

Re: Multiple inheritance, super() and changing signature

2016-06-02 Thread Lawrence D’Oliveiro
On Wednesday, June 1, 2016 at 8:02:14 AM UTC+12, Ben Finney wrote: > (Note that ‘__init__’ is not a constructor, because it operates on the > *already constructed* instance, and does not return anything. Believe it or not, that *is* what “constructor” means in every OO language. Technically it

Re: Multiple inheritance, super() and changing signature

2016-05-31 Thread Steven D'Aprano
On Wed, 1 Jun 2016 02:10 am, Nagy Lc3a1szlc3b3 Zsolt wrote: > Today I come across this problem for the N+1st time. Here are some > classes for the example: A couple of comments... if you're using Python 2, then you may be having trouble because none of the classes shown below inherit from

Re: Multiple inheritance, super() and changing signature

2016-05-31 Thread Ben Finney
Nagy László Zsolt writes: > Today I come across this problem for the N+1st time. Here are some > classes for the example: Thank you for the example. (Note that ‘__init__’ is not a constructor, because it operates on the *already constructed* instance, and does not return

Multiple inheritance, super() and changing signature

2016-05-31 Thread Nagy László Zsolt
Today I come across this problem for the N+1st time. Here are some classes for the example: class Observable: """Implements the observer-observable pattern.""" def __init__(self): # initialization code here... super(Observable, self).__init__() class

Re: multiple inheritance super()

2005-08-01 Thread Steven Bethard
Michele Simionato wrote: I have found out that the more I use OOP, the less I use inheritance Just curious if others had a similar experience. Definitely. Though I think that's partly because I came from a Java background where it's a little more ingrained. Since Python relies heavily on

Re: multiple inheritance super()

2005-07-31 Thread Mike Meyer
Michele Simionato [EMAIL PROTECTED] writes: Mike Meyer: I think you're replying to me, but you didn't include any indication so I can't be sure. Oops, sorry, yes, I was replying to you. These two are cases of what I was talking about when I referred to the Church-Turing thesis. Well, let

Re: multiple inheritance super()

2005-07-30 Thread Michele Simionato
If I understand correcly you have a situation like this: Base | Parent1 Mixin | | | | Children1 Base | Parent2 Mixin | | | | Children2 Base | Parent3 | | Children3 The Base class is pretty general, Parent1, Parent2 and Parent3 are more

Re: multiple inheritance super()

2005-07-30 Thread Mike Meyer
Michele Simionato [EMAIL PROTECTED] writes: I think you're replying to me, but you didn't include any indication so I can't be sure. If I understand correcly you have a situation like this: Base | Parent1 Mixin | | | | Children1 Base | Parent2 Mixin |

Re: multiple inheritance super()

2005-07-30 Thread Michele Simionato
Mike Meyer: I think you're replying to me, but you didn't include any indication so I can't be sure. Oops, sorry, yes, I was replying to you. These two are cases of what I was talking about when I referred to the Church-Turing thesis. Well, let me put it in this way. If a language can

Re: multiple inheritance super()

2005-07-29 Thread Michele Simionato
Sion Arrowsmith That way lies Java well, no, a dynamic language such as Python with the possibility of adding methods on the fly and metaclasses could live pretty well without multiple inheritance. There would be no real loss of power and hopefully less monstruosities such a Zope 2. But maybe

Re: multiple inheritance super()

2005-07-29 Thread Mike Meyer
Michele Simionato [EMAIL PROTECTED] writes: adding methods on the fly and metaclasses could live pretty well without multiple inheritance. There would be no real loss of power and hopefully less monstruosities such a Zope 2. But maybe this is just wishful thinking ... Um, no real loss of

Re: multiple inheritance super()

2005-07-28 Thread Michele Simionato
http://fuhm.org/super-harmful/ That is a pretty good page; I must say that my position is more radical (i.e. it is not super which is harmful, it is multiple inheritance itself that it is harmful: was I going to design a new language I would implement it *without* multiple inheritance).

Re: multiple inheritance super()

2005-07-28 Thread Reinhold Birkenfeld
Michele Simionato wrote: http://fuhm.org/super-harmful/ That is a pretty good page; I must say that my position is more radical (i.e. it is not super which is harmful, it is multiple inheritance itself that it is harmful: was I going to design a new language I would implement it *without*

Re: multiple inheritance super()

2005-07-28 Thread Sion Arrowsmith
Reinhold Birkenfeld [EMAIL PROTECTED] wrote: Michele Simionato wrote: was I going to design a new language I would implement it *without* multiple inheritance). That way lies Java. The number of times I've wished an interface were actually a mixin *shudder* Multiple inheritance can be

Re: multiple inheritance super()

2005-07-28 Thread rafi
Michele Simionato wrote: http://fuhm.org/super-harmful/ That is a pretty good page; I must say that my position is more radical (i.e. it is not super which is harmful, it is multiple inheritance itself that it is harmful: was I going to design a new language I would implement it *without*

Re: multiple inheritance super()

2005-07-27 Thread rafi
Scott David Daniels wrote: I do understand the lookup for foo: foo is provided by both classes A and B and I do not state which one I want to use, so it takes the first one in the list of inherited classes (order of the declaration). However I cannot find an explanation (I may have

Re: multiple inheritance super()

2005-07-27 Thread Michele Simionato
I am mostly using old style (without type unification) init but this motivate the shift for the new style. Is there somewhere a document about this? Yes, see http://www.python.org/2.3/mro.html by yours truly Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list

Re: multiple inheritance super()

2005-07-27 Thread rafi
Michele Simionato wrote: I am mostly using old style (without type unification) init but this motivate the shift for the new style. Is there somewhere a document about this? Yes, see http://www.python.org/2.3/mro.html by yours truly Michele Simionato Thanks a lot -- rafi

Re: multiple inheritance super()

2005-07-27 Thread Mike Meyer
Michele Simionato [EMAIL PROTECTED] writes: I am mostly using old style (without type unification) init but this motivate the shift for the new style. Is there somewhere a document about this? Yes, see http://www.python.org/2.3/mro.html by yours truly I'd also recommend reading URL:

multiple inheritance super()

2005-07-26 Thread km
Hi all, In the following code why am i not able to access class A's object attribute - 'a' ? I wishto extent class D with all the attributes of its base classes. how do i do that ? thanks in advance for enlightment ... here's the snippet #!/usr/bin/python class A(object): def

Re: multiple inheritance super()

2005-07-26 Thread Peter Hansen
km wrote: Hi all, In the following code why am i not able to access class A's object attribute - 'a' ? I wishto extent class D with all the attributes of its base classes. how do i do that ? thanks in advance for enlightment ... here's the snippet #!/usr/bin/python class

Re: multiple inheritance super()

2005-07-26 Thread km
Hi peter, ya got it working :-) now i understand mro better. thanks, KM - On Tue, Jul 26, 2005 at 04:09:55PM -0400, Peter Hansen wrote: km wrote: Hi all, In the following code why am i not able to access class A's object

Re: multiple inheritance super()

2005-07-26 Thread rafi
Peter Hansen wrote: km wrote: Hi all, In the following code why am i not able to access class A's object attribute - 'a' ? I wishto extent class D with all the attributes of its base classes. how do i do that ? [snip] Each class should do a similar super() call, with the appropriate

Re: multiple inheritance super()

2005-07-26 Thread Bengt Richter
On Wed, 27 Jul 2005 12:44:12 +0530, km [EMAIL PROTECTED] wrote: Hi all, In the following code why am i not able to access class A's object attribute - 'a' ? I wishto extent class D with all the attributes of its base classes. how do i do that ? thanks in advance for enlightment ... here's

Re: multiple inheritance super()

2005-07-26 Thread Jeremy Moles
Thought I'm not sure (and don't have time to test) I'd guess it's because you haven't explicitly called the __init__ method chain. i.e., B calls A, C calls B, etc. This is probably where the actual data gets pulled into scope. On Wed, 2005-07-27 at 12:44 +0530, km wrote: Hi all, In the

Re: multiple inheritance super()

2005-07-26 Thread Jeremy Moles
Ignore my last response; just read it fully and realized how dumb my response was. :) On Wed, 2005-07-27 at 12:44 +0530, km wrote: Hi all, In the following code why am i not able to access class A's object attribute - 'a' ? I wishto extent class D with all the attributes of its base