Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Object-Oriented Python Inheritance Super!

Noah Fields
Noah Fields
13,985 Points

Object-Oriented Python, Challenge: Super!, Task 2 error

I am currently attempting to solve the Python challenge "Super!" in the Object-Oriented Python course. I am on step two, in which I need to take a method in "Inventory", and overwrite it in "SortedInventory" using super(). My code may be seen below.

Upon entering this code, I am given the error, "Bummer! Try again!" which doesn't give me very much information on what is wrong here. Running this code in Idle 3.6.0 and calling the method add_item in an Instance of SortedInventory, gives me the following error:

RuntimeError: super(): no arguments

This confuses me because in the associated video, Super Duper, no arguments were given to super() in the parenthesis. What is the error in my code, and how can I fix it?

inventory.py
class Inventory:
    def __init__(self):
        self.slots = []

    def add_item(self, item):
        self.slots.append(item)

class SortedInventory(Inventory):

    def add_item(self, item):
        super().add_item(self, item)

3 Answers

Chris Evergreen
Chris Evergreen
2,857 Points

A Tiny Mistake

Hi there! In your code:

super().add_item(self, item)

You actually don't need to add self in there. So, remove that and you'll get:

super().add_item(item)

And you should be good to go. Best of luck!

Simply curious, why we don't have to put self ? Thanks !

jopapadaki
jopapadaki
7,311 Points

Even with correct answer, right now, the "try again" message appears again...

Spencer Hurrle
Spencer Hurrle
3,128 Points

I was having a similar problem. I thought the override method needed to be init. I changed it to def add_item, the rest was already laid out as you both explained, and mine worked fine. So, ultimately, my code was:

class SortedInventory(Inventory):
    def add_item(self, item):
        super().add.item(item)

If someone could help me understand why we're not using init though, I'd really appreciate that! Is def add_item a direct reference to the method in the superclass? I thought the only direct reference to the superclass was the line starting with super()... Again, any help or further explanation would be great!