[Steven D'Aprano]
>    obj = Aardvark(27, spam=3, eggs=5, cheese=True)
> 
> So you look up help(Aardvark), and it tells you that the signature is
> 
>    Aardvark.__init__(self, foo)
> 
> What the hell? If Aardvark.__init__ only takes a single argument
This is wrong! This would at some point down the line throw an error
   TypeError: __init__() got an unexpected keyword argument 'eggs‘
(or at some point **kwargs are being accepted and not passed on to super which 
would be terrible on its own).

The whole point I was trying to make is: If it doesn’t make any sense to init a 
class with **kwargs: why write down that it would (or even **could**) accept 
them? Shouldn’t the init tell you something like 'If you instantiate this class 
then this is everything you can give me'? Well, right now in addition it says 
'Just give me anything with keywords‘. I would think that something like 'Oh, 
and if I am in the middle of an MRO: I will pass everything down the line‘ 
would be a much better description of it’s true intentions instead.


[Carl Smith]
> By using **kargs in the constructor and the call
> to `super`, you are indicating that the signature passes through
But can you be certain? Couldn’t someone have just used a `kargs.pop('eggs')`? 
Okay. You could argue that they probably wouldn’t have done so. But for making 
automated documentation it probably would be useful to make sure it didn’t 
happen.

I think that (as Raymond Hettinger once said) 'super is super', but can’t you 
make it a bit smarter with telling it: 'Hey - If you don’t expect 'eggs', keep 
calm, it probably (or rather certainly) wasn’t meant for you so just pass it on 
to your super'.


Best,
Michael
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to