Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: Super does not take Key word arguments?

Tags:

People also ask

What is super()__ init__ in Python?

When you initialize a child class in Python, you can call the super(). __init__() method. This initializes the parent class object into the child class. In addition to this, you can add child-specific information to the child object as well.

What does super() do in Python?

The super() function is used to give access to methods and properties of a parent or sibling class. The super() function returns an object that represents the parent class.

Can we pass arguments in super?

In AS2, you can pass parameters to a super class's constructor using super() . This is handy, but what if your constructor accepts an undefined number of parameters, and you want to pass them all to your super constructor (think of the Array class, for instance)?

When to use super init Python?

The “__init__” is a reserved method in python classes. It is known as a constructor in Object-Oriented terminology. This method when called, allows the class to initialize the attributes of the class. The super() function allows us to avoid using the base class name explicitly.


First, here is my code:

class Enemy():
    def __init__(self, name, hp, damage):
        self.name = name
        self.hp = hp
        self.damage = damage


    def is_alive(self):
        """Checks if alive"""
        return self.hp > 0

class WildBoar(Enemy):
    def __init__(self):
        super(WildBoar, name="Wild Boar", hp=10, damage=2).__init__()

class Marauder(Enemy):
    def __init__(self):
        super(Marauder, name="Marauder", hp=20, damage=5).__init__()


class Kidnappers(Enemy):
    def __init__(self):
        super(Kidnappers, name="The Kidnappers", hp=30, damage=7).__init__()

When I compile this I get this error:

super(WildBoar, name="Wild Boar", hp=10, damage=2).__init__()
TypeError: super does not take keyword arguments

I tried looking around for any kind of help but I couldn't find anything. I also have some Kwargs in some other class's supers, but these are the ones raising any kind of issues (as of right now). So what could be causing this? I've also seen someone say that putting a super in the base class will fix it, but it didn't work (I passed in the same arguments that are in the Base class's __init__).


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!