[Python-ideas] Keyword for direct pass through of kwargs to super
brenbarn at brenbarn.net
Sat May 26 13:57:35 EDT 2018
On 2018-05-26 02:22, Michael Lohmann wrote:
> Whenever you give any kwargs when directly instantiating `A` they
> will be passed down to super which in this case is `object`. And now
> to the follow-up question: Can you tell me which kwargs object takes
> as an input for it’s __init__? So does it EVER make ANY sense to
> specify them if you DIRECTLY create an instance of `A`?
> But now let’s say your MRO is `SuperClass, A, B`, then A should
> better be able to forward the kwargs, so currently you need to
> directly hand them to `A` and rely on the fact that it passes them on
> to `B`.
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). But you
can't, because if you pass on extra **kwargs, that will fail if the
class inherits directly from object, but if you don't pass on extra
**kwargs, that will fail if the class doesn't inherit directly from
object. Is that correct?
I agree that it is somewhat somewhat awkward that "is this the top
class in the hierarchy" is something that has to be known when writing a
class. I think this would be ameliorated by having "object" accept and
ignore extra arguments. (I seem to recall that was decided to be a bad
idea at some time in the past, though.) But I don't really see how your
solution of magically making kwargs appear and disappear is a good
solution to that problem.
"Do not follow where the path may lead. Go, instead, where there is no
path, and leave a trail."
More information about the Python-ideas