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

Greg Ewing greg.ewing at canterbury.ac.nz
Sun May 27 08:45:09 EDT 2018


Brendan Barnwell wrote:

>     If I understand correctly, the essence of your argument seems to be 
> that you want be able to write a class A, and you want to be able to use 
> that class EITHER as the top of an inheritance chain (i.e., have it 
> inherit directly from object) OR in the middle of an inheritance chain 
> (i.e., inheriting from some other class, but not object).

This shouldn't be a problem if each method along the way
absorbs all the arguments it knows about, and only passes
on the ones it doesn't. E.g.

class A:
     def __init__(self, alpha, **kwds):
         print("alpha =", alpha)
         super().__init__(**kwds)

class B(A):
     def __init__(self, beta, **kwds):
         print("beta =", beta)
         super().__init__(**kwds)

b = B(alpha = 17, beta = 42)

Both A and B here pass on a **kwds argument, but by the
time it get to object, there are no arguments left, so
it's fine.

-- 
Greg



More information about the Python-ideas mailing list