Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
Python Super() With __Init__() Method
Next article icon

Python Runtimeerror: Super() No Arguments

Last Updated : 20 Feb, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Python, a versatile programming language, provides developers with a powerful toolset for creating complex applications. However, like any programming language, it comes with its share of challenges. One such issue that developers might encounter is the "RuntimeError: super(): no arguments." This error can be puzzling for those new to Python 3, but fear not; in this article, we'll explore the nature of this error, understand why it occurs, and delve into different approaches to resolve it.

What is RuntimeError: super(): No Arguments Error?

The "RuntimeError: super(): no arguments" error is a common stumbling block for developers, especially when transitioning from Python 2 to Python 3. This error occurs when using the super() function without providing any arguments, causing confusion and disrupting the inheritance chain. Understanding the reasons behind this error is crucial for finding effective solutions.

Why does RuntimeError: super(): No Arguments occur?

Below are some of the examples by which RuntimeError: super(): No Arguments in Python:

Change in super() Behavior in Python

Python3 introduced a more explicit approach to the super() function, requiring the developer to pass the current class and instance explicitly. Failing to do so results in the RuntimeError.

Python3
class A:     @staticmethod     def m() -> int:         return 1  class B(A):     @staticmethod     def m() -> int:         return super().m()    B().m() 

Output:

Hangup (SIGHUP)
Traceback (most recent call last):
File "Solution.py", line 11, in <module>
B().m()
File "Solution.py", line 9, in m
return super().m() # passes, but should not
RuntimeError: super(): no arguments

Multiple Inheritance Ambiguity

If your code involves multiple inheritance, not providing arguments to super() can lead to ambiguity in determining the method resolution order (MRO), causing the RuntimeError.

Python3
class Works(type):     def __new__(cls, *args, **kwargs):         print([cls,args]) # outputs [<class '__main__.Works'>, ()]         return super().__new__(cls, args)  class DoesNotWork(type):     def __new__(*args, **kwargs):         print([args[0],args[:0]]) # outputs [<class '__main__.doesNotWork'>, ()]         return super().__new__(args[0], args[:0])  DoesNotWork()  

Output:

Hangup (SIGHUP)
Traceback (most recent call last):
File "Solution.py", line 11, in <module>
DoesNotWork() # gets "RuntimeError: super(): no arguments"
File "Solution.py", line 9, in __new__
return super().__new__(args[0], args[:0])
RuntimeError: super(): no arguments

Solution for RuntimeError: super(): No Arguments

Below are some of the solutions for RuntimeError: super(): No Arguments error in Python:

Explicitly Pass Class and Instance to super()

To address the change in super() behavior in Python 3, explicitly pass the current class and instance as arguments. For example:

Python3
class ParentClass:     def __init__(self):         print("ParentClass constructor")  class IntermediateClass(ParentClass):     def __init__(self):         super(IntermediateClass, self).__init__()           print("IntermediateClass constructor")  class ChildClass(IntermediateClass):     def __init__(self):         super(ChildClass, self).__init__()          print("ChildClass constructor")  child_instance = ChildClass() 

Output
ParentClass constructor IntermediateClass constructor ChildClass constructor

Resolve Multiple Inheritance Ambiguity

If your code involves multiple inheritance, carefully review the class hierarchy and ensure that the super() calls are properly aligned with the desired MRO. Adjust the order of the base classes if necessary.

Python3
class ParentA:     def show(self):         print("Method in ParentA")  class ParentB:     def show(self):         print("Method in ParentB")  class Child(ParentA, ParentB):     def show(self):         super(Child, self).show()           print("Method in Child")   child_instance = Child()   child_instance.show() 

Output
Method in ParentA Method in Child

Check and Correct Class Structure

Review your class structure and verify that the super() calls are placed correctly within the methods. Ensure that the inheritance chain is well-defined, and classes are designed according to the intended hierarchy.

Python3
class BaseClass:     def __init__(self):         print("BaseClass constructor")  class IntermediateClass(BaseClass):     def __init__(self):         super(IntermediateClass, self).__init__()          print("IntermediateClass constructor")  class ChildClass(IntermediateClass):     def __init__(self):         super(ChildClass, self).__init__()          print("ChildClass constructor")   child_instance = ChildClass() 

Output
BaseClass constructor IntermediateClass constructor ChildClass constructor

Conclusion

The "RuntimeError: super(): no arguments" error in Python 3 can be a stumbling block for developers, but armed with an understanding of its origins and the right solutions, it can be overcome. By embracing the explicit nature of super() in Python 3, resolving multiple inheritance ambiguity, and ensuring a well-structured class hierarchy, developers can navigate through this error and produce robust and efficient Python code.


Next Article
Python Super() With __Init__() Method
author
vanshgarg23
Improve
Article Tags :
  • Python
  • Python Programs
  • Python Errors
Practice Tags :
  • python

Similar Reads

  • Get Current time in Python
    In this article, we will know the approaches to get the current time in Python. There are multiple ways to get it. The most preferably date-time module is used in Python to create the object containing date and time. DateTime object in Python is used to manage operations involving time-based data. d
    2 min read
  • How To Create a Countdown Timer Using Python?
    In this article, we will see how to create a countdown timer using Python. The code will take input from the user regarding the length of the countdown in seconds. After that, a countdown will begin on the screen of the format 'minutes: seconds'. We will use the time module here. Step-by-Step Approa
    2 min read
  • How to Fix - Timeouterror() from exc TimeoutError in Python
    We can prevent our program from getting stalled indefinitely and gracefully handle it by setting timeouts for external operations or long-running computations. Timeouts help in managing the execution of tasks and ensuring that our program remains responsive. In this article, we will see how to catch
    3 min read
  • Create a Countdown Timer for New Year Using Python
    Many of us eagerly wait the arrival of the New Year. A countdown timer is a way to keep track of the remaining time until midnight. To achieve this, we'll utilize Python's datetime and time modules. The datetime module allows us to work with dates and times, while the time module helps in creating d
    3 min read
  • Python Super() With __Init__() Method
    In object-oriented programming, inheritance plays a crucial role in creating a hierarchy of classes. Python, being an object-oriented language, provides a built-in function called super() that allows a child class to refer to its parent class. When it comes to initializing instances of classes, the
    4 min read
  • Python - Time Strings to Seconds in Tuple List
    Given Minutes Strings, convert to total seconds in tuple list. Input : test_list = [("5:12", "9:45"), ("12:34", ), ("10:40", )] Output : [(312, 585), (754, ), (640, )] Explanation : 5 * 60 + 12 = 312 for 5:12. Input : test_list = [("5:12", "9:45")] Output : [(312, 585)] Explanation : 5 * 60 + 12 = 3
    7 min read
  • How to fix "SyntaxError: invalid character" in Python
    This error happens when the Python interpreter encounters characters that are not valid in Python syntax. Common examples include: Non-ASCII characters, such as invisible Unicode characters or non-breaking spaces.Special characters like curly quotes (“, ”) or other unexpected symbols.How to Resolve:
    2 min read
  • What Does Super().__Init__(*Args, **Kwargs) Do in Python?
    In Python, super().__init__(*args, **kwargs) is like asking the parent class to set itself up before adding specific details in the child class. It ensures that when creating an object of the child class, both the parent and child class attributes are initialized correctly. It's a way of saying, In
    4 min read
  • Python program to print current year, month and day
    In this article, the task is to write a Python Program to print the current year, month, and day. Approach: In Python, in order to print the current date consisting of a year, month, and day, it has a module named datetime. From the DateTime module, import date classCreate an object of the date clas
    1 min read
  • Convert string to DateTime and vice-versa in Python
    A common necessity in many programming applications is dealing with dates and times. Python has strong tools and packages that simplify handling date and time conversions. This article will examine how to effectively manipulate and format date and time values in Python by converting Strings to Datet
    6 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences