Python Forum
[Python Core] Keyword for direct passthrough of **kwargs to super().__init__
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Python Core] Keyword for direct passthrough of **kwargs to super().__init__
#1
First of all: I just started programming in Python a couple of months ago, so please be patient if I ask a stupid question. I started this question on Stackoverflow but it might be more appropriated here...


Could there be a "magical keyword" (which obviously only works if no **kwargs is specified) so that the
__init__(*args, some_keyword=None, ***pass_through_kwargs)
so that all unexpected kwargs (everything that would be in kwargs if they were specified instead) are directly passed through to the super().__init__? In an unmodifiable way in the background and without the users active part of putting them in the super().__init__ themselves. This would make the readability much easier and they could be safely ignored by autocomplete and automated documentation for this class.

In the following diagram Mouse is ever only instantiated with let's say a name. Just to make the super-calls (in red) down the line work I have to add **kwargs (to specify the number_of_holes the cheese has) and hand them over by hand. Can't I just tell Mouse and Animal "Whatever you don't know: just pass it directly down to super()"?
[Image: gBnXO.png]

I want something like this to work:
class Animal:
    def __init__(self, species, ***pass_through_kwargs):
        self.species = species
        super().__init__()
class Mouse(Animal):
    def __init__(self, name, ***pass_through_kwargs):
        self.name = name
        super().__init(species="Mouse")
class Cheese:
    def __init__(self, num_of_holes=0):
        self.num_of_holes = num_of_holes
class MickeyMouse(Mouse, Animal):
    def __init__(self):
        super().__init__(name='Mickey Mouse', num_of_holes=2)
Reply


Messages In This Thread
[Python Core] Keyword for direct passthrough of **kwargs to super().__init__ - by miallo - May-25-2018, 04:36 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020