Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subclass init method only calls base initializer method

I have a derived class whose __init__ method only calls super().__init(...). However, the list of arguments to the super class is very long, which makes for a long list of mostly boiler plate:

def __init__(self, dataset, updater=None,
                 start_date=None,
                 end_date=None,
                 fill_missing_only=False,
                 total_sync: bool = False,
                 force: bool = False,
                 allow_missing: bool = False,
                 backfill=''):
        super().__init__(self, dataset, updater,start_date, end_date,fill_missing_only,total_sync,force,allow_missing,backfill)

Is there a way to remove this and have the subclass call the base's init() method automatically?

like image 875
user1742188 Avatar asked May 23 '26 02:05

user1742188


1 Answers

I see two possibilities:

  • Just omit the __init__ method in the subclass - if you don't in fact override anything.

  • Use

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

    if you do some other things besides the super().__init__ call but don't need all arguments.

like image 180
MSeifert Avatar answered May 25 '26 14:05

MSeifert