python 3 error RuntimeError: super(): no arguments
Not 100% solution to the answer, but same error. Posted with love for Googlers who have the same issue as me.
Using Python 3, I got this error because I forgot to include self
in the method. Simple thing, but sometimes the most simple things trip you up when you're tired.
class foo(object):
def bar(*args):
super().bar(*args)
=> RuntimeError: super(): no arguments
Remember to include your self
class foo(object):
def bar(self, *args):
super().bar(*args)
Every time you use super() in a method, you need to be in an instance method or a class method. Your staticmethod
s don't know what their superclasses are. Observe:
class Funky:
def groove(self):
print("Smooth")
@staticmethod
def fail():
print("Ouch!")
@classmethod
def wail(cls):
print("Whee!")
class Donkey(Funky):
def groove(self):
print(super())
@staticmethod
def fail():
try:
print(super())
except RuntimeError as e:
print("Oh no! There was a problem with super!")
print(e)
@classmethod
def wail(cls):
print(super())
a_donkey = Donkey()
a_donkey.groove()
a_donkey.fail()
a_donkey.wail()
Outputs:
<super: <class 'Donkey'>, <Donkey object>>
Oh no! There was a problem with super!
super(): no arguments
<super: <class 'Donkey'>, <Donkey object>>
Here's your code, debugged and with some extra functionality and tests:
class Project:
def __init__(self, name="", job="", **kwargs):
super().__init__(**kwargs)
self.name = name
self.job = job
def display(self):
print("name: ", self.name)
print("job: ", self.job)
@staticmethod
def prompt_init():
return dict(name=input("name: "), job=input("job: "))
class Progress(Project):
def __init__(self, progress="", **kwargs):
super().__init__(**kwargs)
self.progress = progress
def display(self):
super().display()
print("progress: ", self.progress)
@staticmethod
def prompt_init():
parent_init = Project.prompt_init()
progress = input("your progress: ")
parent_init.update({
"progress": progress
})
return parent_init
class New:
def __init__(self):
self.project_list = []
def display_project(self):
for project in self.project_list:
project.display()
print()
def add_project(self):
init_args = Project.prompt_init()
self.project_list.append(Project(**init_args))
def add_progress(self):
init_args = Progress.prompt_init()
self.project_list.append(Progress(**init_args))
my_list = New()
my_list.add_project()
my_list.add_progress()
my_list.display_project()