>
> 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:
>
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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:
>
>
>> 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
>> 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
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
> 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:
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
> >>
>
> 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
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()
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,
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
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*
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.
>
>
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
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
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
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
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
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
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
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
|
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
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
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
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).
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*
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
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*
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
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
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
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:
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
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
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
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
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
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
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
53 matches
Mail list logo