[Python-Dev] arguments policy: **kwargs.pop()

Christian Tismer tismer at stackless.com
Fri Apr 11 23:01:50 CEST 2014


Hi Chris,

On 11/04/14 21:50, Chris Barker wrote:
> On Thu, Apr 10, 2014 at 7:12 PM, Christian Tismer <tismer at stackless.com>wrote:
> 
>> Then I rather often see things like this:
>>
>> class someclass(object):
>>     # note that there is no comment about argument destruction...
>>
>>     def __init__(self, **kwargs):
>>         first_arg = kwargs.pop('option_1', somedefault)
>>         ...
>>         nth_arg = kwargs.pop('option_n', somedefault')
>>         ...
>>
> 
> While it's been clarified that this isn't dangerous, I find it to be a
> really annoying style, as you've lost the opurtuniyt to docuemnt somethign
> in the signature. Is:
> 
>     def __init__(self, option_1=some_default, option_n=some_default,
> **kwargs):
>         first_arg = kwargs.pop('option_1')
>         nth_arg = kwargs.pop('option_n')
> 
> *that* much harder to write?
> 
> And many of these come with virtually no docstring, either.....

Thank you for re-validating my rant, after my wrong start was clarified.
Yes, the style is of course annoying, still.

This is the style of
"""hey look how cool I am, just taking an interface, picking args if
they happen to be there and otherwise not treating them""".

So while I'm still ashamed of my mis-interpretion, I am happy to still
not like that very much.

At least for myself, I like to be way more explicit and tell actively
what I expect as arguments, what I do care about and what not, just to
make sure that people see right by looking at the interface what they
may ignore and what they should probably put in as an argument.

Actually, putting so many defaults in without documenting that in the
interface is this new-fangled sloppiness that is perceived as cool-ness.

May be I am getting old, but I dislike this and tend to tell much more
in the interface. And not in the 35th iteration, but when writing the
first public version.

This is because I don't want to throw an interface at somebody, but to
discuss and improve it, and for that I put comments in that invite to
agree or create a better version.

I have these style problems with several modules that I am reluctant to
use, therefore. I know that I'm pretty alone with that. But my idea
of a published module is such that it should try to motivate why it is
doing things in which way, and why it thinks this is good to do.

Doing that not and nothing instead is my definition of "sloppy".

(interested people may get the actual module from me why this came up)

cheers -- Chris


-- 
Christian Tismer             :^)   <mailto:tismer at stackless.com>
Software Consulting          :     Have a break! Take a ride on Python's
Karl-Liebknecht-Str. 121     :    *Starship* http://starship.python.net/
14482 Potsdam                :     PGP key -> http://pgp.uni-mainz.de
phone +49 173 24 18 776  fax +49 (30) 700143-0023
PGP 0x57F3BF04       9064 F4E1 D754 C2FF 1619  305B C09C 5A3B 57F3 BF04
      whom do you want to sponsor today?   http://www.stackless.com/


More information about the Python-Dev mailing list