Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why accept kwargs but not use them?

I was looking at the Django source code today and I noticed this:

class DjangoTestSuiteRunner(object):
    def __init__(self, verbosity=1, interactive=True, failfast=True, **kwargs):
        self.verbosity = verbosity
        self.interactive = interactive
        self.failfast = failfast

Why would they accept kwargs in the constructor but then not do anything with them?

like image 459
Zameer Manji Avatar asked Jan 17 '23 13:01

Zameer Manji


1 Answers

This pattern can make backwards/forwards compatibility easier. If the newer/older version of the code has more/less parameters then you won't break everything.

Also, when you are inheriting this class (for example with mixins) it can be convenient to just accept everything.

Imho it's not a pretty pattern to use, but it works.

like image 127
Wolph Avatar answered Jan 29 '23 12:01

Wolph