[Python-ideas] Keyword for direct pass through of kwargs to super

Michael Lohmann mial.lohmann at gmail.com
Sun May 27 14:07:18 EDT 2018


> Everything my idea has to offer really is just reasonable if you don’t have single inheritance only

I would like to correct myself immediately on that one: In the Pizza-example (from yesterday as well) it would be possible to overwrite the default price of the HawaiianPizza with the merging of bypassed kwargs with the ones from the call itself. Let us assume that the exemption of the 10$ price for all HawaiianPizzas would be a Family-sized pizza for 20$:

    class Pizza:
        def __init__(self, *, size, price):
            print("The price of this %s pizza is:", (size, price))

    @cooperative
    class HawaiianPizza(Pizza):
        def __init__(self, *, pineapple="chunked", size=8):
            print("This pizza has %s pineapple." % pineapple)
            super().__init__(price=10, size=size)

    class FamilyHawaiianPizza(HawaiianPizza):
        def __init__(self, *, pineapple="chunked"):
            super().__init__(price=20, size=20, pineapple=pineapple) #This would overwrite the price of the HawaiianPizza

But this would not be the real intention of the usage, but just a side effect of correctly handling a simple diamond-like hierarchy. The reason that bypassed kwargs should overwrite them is that they come from up the MRO and so obviously should have priority.

Sorry to spam you all,
Have a nice Sunday! Michael


More information about the Python-ideas mailing list