Isn't .super() a bit inconsistent?

So I’m doing the exercises of this link:

I got number 1 and number 2.

In exercise 3 i first tried:


But then, I was corrected with:


I understand that super is going to the parent class List and calling it’s append method on my SortedList class.
But I tried self.append(value) because I thought that since SortedList is a child of List, and since I didn’t rewrite any constructors or anything, it would also inherit the append method. But my code didn’t work, so I guess I was wrong.

So, in the next exercise (number 4) I typed:


But now, it tells me that this is also wrong, and that I should have typed:


Why do I have to use super() in 3, but can’t use it in 4?
And why can’t I use self in 3, but can in 4?

It’s probably something really simple, but right now I’m not seeing it.
Isn’t this a bit inconsistent?


Oh wait! Is it because of recursion?
Maybe by trying self.append(value) in the definition of theappend method, I’m calling the method over and over again?
So maybe both self and super() both work, and I just can’t use self.method in the definition of method… Is that it?

Antonio, yes, when you call append() within a method called append(), you’ll likely enter an infinite loop due to unbridled recursion.

As for other methods, such as sort(), I’m a bit on the fence as to whether to use super() , but I tend to lean towards using it to more or less acknowledge that you are inheriting from list.

In this case, it works either way. If you were overriding a number of other methods, maybe asking count() to return the indices of found elements, or index() to return the indices of all elements, rather than only the first, things might be more confused, so you might use super() just to help keep track of built-in vs overridden methods.

1 Like