[Python-3000] PEP3102 Keyword-Only Arguments; Signature

Guido van Rossum guido at python.org
Tue Aug 15 02:26:42 CEST 2006

On 8/14/06, Jim Jewett <jimjjewett at gmail.com> wrote:
> On 8/14/06, Steven Bethard <steven.bethard at gmail.com> wrote:
> > On 8/14/06, Guido van Rossum <guido at python.org> wrote:
> > > I believe the PEP doesn't address the opposite use case: positional
> > > arguments that should *not* be specified as keyword arguments.
> ...
> > It would be really nice in the example above to mark ``self`` in
> > ``__call__`` as a positional only argument.
> Would this have to be in the standard function prologue, or would it
> be acceptable to modify a function's Signature object?
> As I see it, each argument can be any combination of the following:
>     positional
>     keyword
>     named
>     defaulted
>     annotated
> I can see some value in supporting all 32 possibilities, but doing it
> directly as part of the def syntax might get awkward.

Perhaps. Though you're making it seem worse than it is by adding
annotated (which should be considered completely orthogonal to the
rest, and may not combine with everything else).

> Most arguments are both positional and keyword.  The bare * will
> support keyword-only, and you're asking for positional-only.  (An
> argument which is neither positional nor keyword doesn't make sense.)
> Today (except in extension code), an argument that isn't named only
> appears courtesy of *args or **kwargs.
> Today, named + keyword <==> defaulted

I'm not sure I follow. You seem to be perpetuating the eternal
misunderstanding that from the caller's POV this is not a keyword

  def foo(a): pass

In fact, calling foo(a=1) is totally legal.

> Today, arguments are not annotated.
> Would it be acceptable if functions contained a (possibly implicit)
> Signature object, and the way to get the odd combinations were through
> modifying that?
> For example:
>     def unnamedargs(func):
>         for arg in func.Signature:
>             arg.name=None
>         return func
> ...
>         @unnamedargs
>         def write(self, s):

This seems a last-resort approach; I'd rather do something less
drastic. Unfortunately the more I think about it the less I like using
'**' without a following name for this feature.

PS whenever you respond to something it becomes a new thread in Gmail.
Is your mail app perhaps not properly inserting In-reply-to headers?
Or do you forge a reply by creating a new message with the same
subject and "Re:" prepended?

--Guido van Rossum (home page: http://www.python.org/~guido/)

More information about the Python-3000 mailing list