Accessing methods from superclasses

super is a built-in class that can be used to access an attribute belonging to an object's superclass.

Note

The Python official documentation lists super as a built-in function. But it's a built-in class, even if it is used like a function:

>>> super
<class 'super'>

Its usage is a bit confusing when you are used to accessing a class attribute or method by calling the parent class directly and passing self as the first argument. This is really old pattern but still can be found in some codebases (especially in legacy projects). See the following code:

class Mama:  # this is the old way
    def says(self):
        print('do your homework')

         
class Sister(Mama):
    def says(self):
        Mama.says(self)
        print('and clean your bedroom')

When ...

Get Expert Python Programming - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.