[Python-3000] PEP3102 Keyword-Only Arguments

Nick Coghlan ncoghlan at gmail.com
Tue Aug 15 08:44:25 CEST 2006

Steven Bethard wrote:
> [Steven Bethard]
>> It would be really nice in the example above to mark ``self`` in
>> ``__call__`` as a positional only argument.
> [Nick Coghlan]
>> However, I'm also wondering if we need an actual syntax, or if a simple
>> convention would do the trick: start the names of positional-only 
>> arguments
>> with an underscore.
> That would certainly be good enough for me.  As long as it's
> documented and there's somewhere to point to when someone does it
> wrong, it solves my problem.

Putting something in PEP 8's section on naming conventions should do the trick 
(along with updating the standard library so that things like UserDict that 
accept arbitrary **kwargs use it for their positional arguments).

That would also serve as a reminder that the support for keyword arguments 
means that the parameter *names* are part of the public interface of a Python 
function along with their positions and types.

> [Guido van Rossum]
>> Hm... and perhaps we could forbid keyword arguments starting with an
>> underscore in the call syntax?
> -0.  As long as the convention exists somewhere, I don't think this
> buys us too much. I think supplying a keyword argument when you should
> be using a positional is about the same level of
> willing-to-shoot-yourself-in-the-foot as using attributes that are
> supposed to be private (the other place where leading underscores are
> suggested).

That's exactly the comparison I was aiming for - you *can* if you really have 
to, but you also *shouldn't*. And if you do, you'd better including a comment 
explaining why you have to if you don't want any reviewers complaining about it ;)


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-3000 mailing list