super() in Python 3

אורי uri at speedy.net
Tue Jul 16 06:08:41 EDT 2019


Hi,

1. When we use super() in Python 3, we don't pass it the first argument
(self). Why?

What happens if the first argument is not self?

def __init__(self, *args, **kwargs):
    super().__init__(*args, **kwargs)

I think it would make more sense to use something like
self.super().__init__(*args, **kwargs) or something like this.

2. I want to override a function called build_suite in an inherited class.
The function receives an argument "test_labels" which I want to change (I
define it if it's not defined), but I don't do anything with the argument
"extra_tests". Is it possible to include "extra_tests" in *args, **kwargs
and how? I think maybe they will release another version in the future
without "extra_tests", or with additional arguments, and I don't want to
have to change my code then.

def build_suite(self, test_labels=None, extra_tests=None, **kwargs):
    ....
    return super().build_suite(test_labels=test_labels,
extra_tests=extra_tests, **kwargs)

(Notice there are no *args)

Thanks!
אורי
uri at speedy.net



More information about the Python-list mailing list