[Python-ideas] Keyword only argument on function call

Ethan Furman ethan at stoneleaf.us
Mon Sep 10 17:00:58 EDT 2018


On 09/10/2018 12:52 PM, Chris Barker via Python-ideas wrote:

> I've spent this whole thread thinking: "who in the world is writing code 
> with a lot of spam=spam arguments? If you are transferring that much 
> state in a function call, maybe you should have a class that holds that 
> state? Or pass in a **kwargs dict?

> So still looking for a compelling use-case

In my day job I spend a lot of time writing/customizing modules for a 
framework called OpenERP (now Odoo*).  Those modules are all subclasses, 
and most work will require updating at least a couple parent metheds -- 
so most calls look something like:

   def a_method(self, cr, uid, ids, values, context=None):
     ...
     super(self, parent).a_method(cr, uid, ids, values, context=context)

Not a perfect example as these can all be positional, but it's the type 
of code where this syntax would shine.

I think, however, that we shouldn't worry about a lead * to activate it, 
just use a leading '=' and let it show up anywhere and it follows the 
same semantics/restrictions as current positional vs keyword args:

   def example(filename, mode, spin, color, charge, orientation):
       pass

   example('a name', 'ro', =spin, =color, charge=last, =orientation)

So +0 with the above proposal.

--
~Ethan~


More information about the Python-ideas mailing list