[Python-ideas] keyword arguments everywhere (stdlib) - issue8706

Arnaud Delobelle arnodel at gmail.com
Sat Mar 3 14:51:12 CET 2012

On 2 March 2012 21:48, Guido van Rossum <guido at python.org> wrote:
> On Fri, Mar 2, 2012 at 1:09 PM, Arnaud Delobelle <arnodel at gmail.com> wrote:
>> On 2 March 2012 20:00, Guido van Rossum <guido at python.org> wrote:
>>> On Mar 2, 2012 11:43 AM, "Arnaud Delobelle" <arnodel at gmail.com> wrote:
>>>> On 2 March 2012 19:28, Guido van Rossum <guido at python.org> wrote:
>>>> > I would actually like to see a syntactic feature to state that an
>>>> > argument *cannot* be given as a keyword argument (just as we already
>>>> > added syntax to state that it *must* be a keyword).
>>>> There was a discussion about this on this list in 2007.  I wrote some
>>>> decorators to implement it this functionality.  Here's one at
>>>> http://code.activestate.com/recipes/521874-functions-with-positional-only-arguments/?in=user-4059385
>>>> (note that it didn't attract a lot of attention !).  The recipe also
>>>> refers to the original discussion.
>>> I've written such decorators too, but they've got quite a bit of overhead...
>> The one in the above recipe (which is for 2.X) doesn't incur any
>> runtime overhead - although it is a bit hackish as it changes the
>> 'co_varnames' attribute of the function's code object.
> So it's not written in Python -- it uses CPython specific hacks.

True.  OTOH if you decided to put such a decorator in CPython's
standard library (and I'm not talking about this specific
implementation of the decorator), then implementors of other Pythons
would have to provide the same functionality.  We would then get the
ability to have positional only arguments free of overhead without
having to make the syntax of function signatures even more complex.

Also, a decorator would be a signal to users that positional only
argument are not often necessary, whereas offering syntactical support
for them may encourage over use of the feature.


More information about the Python-ideas mailing list