[Python-ideas] Keyword-only arguments?

Chris Kaynor ckaynor at zindagigames.com
Wed Jun 17 21:01:08 CEST 2015


On Wed, Jun 17, 2015 at 11:58 AM, Amber Yust <amber.yust at gmail.com> wrote:

> One thing that has been a source of bugs and frustration in the past is
> the inability to designate a named keyword argument that cannot be passed
> as a positional argument (short of **kwargs and then keying into the dict
> directly). Has there been any previous discussion on the possibility of a
> means to designate named arguments as explicitly non-positional?
>
> Not a solid proposal, but to capture the essential difference of what I'm
> thinking of, along the lines of...
>
>     def foo(bar, baz=None, qux: None):
>
> where bar is a required positional argument, baz is an optional argument
> that can have a value passed positionally or by name, and qux is an
> optional argument that must always be passed by keyword.
>
> Such a means would help avoid cases where a misremembered function
> signature results in a subtle and likely unnoticed bug due to unintended
> parameter/argument mismatch.
>
> (It's possible that this has been discussed before - a cursory search of
> python-ideas didn't bring up any direct discussion, but I may have missed
> something. If you have a link to prior discussion, please by all means
> point me at it!)
>

This feature was added to Python 3 about 9 years ago, see
https://www.python.org/dev/peps/pep-3102/. A quick search for "python
keyword only arguments" on Google found it.

Guido's time machine strikes again!

Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150617/43630695/attachment.html>


More information about the Python-ideas mailing list