I have encountered situations like this, and generally I just use **kwargs
for non-critical  and handle the parameter management in the body of the
function.

This also makes it easier to pass the arguments to another function.  You
can use a dict comprehension to copy over the keys you want, then unpack
them as arguments to the next function.

On Thu, Sep 6, 2018 at 6:16 AM Anders Hovmöller <bo...@killingar.net> wrote:

> I have a working implementation for a new syntax which would make using
> keyword arguments a lot nicer. Wouldn't it be awesome if instead of:
>
>         foo(a=a, b=b, c=c, d=3, e=e)
>
> we could just write:
>
>         foo(*, a, b, c, d=3, e)
>
> and it would mean the exact same thing? This would not just be shorter but
> would create an incentive for consistent naming across the code base.
>
> So the idea is to generalize the * keyword only marker from function to
> also have the same meaning at the call site: everything after * is a kwarg.
> With this feature we can now simplify keyword arguments making them more
> readable and concise. (This syntax does not conflict with existing Python
> code.)
>
> The full PEP-style suggestion is here:
> https://gist.github.com/boxed/f72221e7e77370be3e5703087c1ba54d
>
> I have also written an analysis tool you can use on your code base to see
> what kind of impact this suggestion might have. It's available at
> https://gist.github.com/boxed/610b2ba73066c96e9781aed7c0c0b25c . The
> results for django and twisted are posted as comments to the gist.
>
> We've run this on our two big code bases at work (both around 250kloc
> excluding comments and blank lines). The results show that ~30% of all
> arguments would benefit from this syntax.
>
> Me and my colleague Johan Lübcke have also written an implementation that
> is available at: https://github.com/boxed/cpython
>
> / Anders Hovmöller
> _______________________________________________
> Python-ideas mailing list
> Python-ideas@python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
_______________________________________________
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