[Python-ideas] Positional only arguments

Steven Bethard steven.bethard at gmail.com
Sun May 20 19:13:01 CEST 2007


On 5/18/07, Adam Olsen <rhamph at gmail.com> wrote:
> On 5/18/07, Steven Bethard <steven.bethard at gmail.com> wrote:
> >
> > In the hopes of keeping this discussion enough on track that we can
> > eventually come to a conclusion, I thought I'd just take a couple
> > minutes to summarize the proposals so far. I'm looking at the
> > following function as an example::
> >
> >     def f(a, b=None, *, c=42, **kwargs)
> >
> > where ``a`` and ``b`` should be positional-only and ``c`` should be
> > keyword-only. Here are the alternatives I've seen so far:
>
> * Use ** for keyword-only and * for positional-only:
>
>     def (a, b=None, *, **, c=42, **kwargs):
>
>   Pro: backwards compatible, reuses existing meanings
>   Con: requires new syntax, changes keyword-only PEP

I like the idea of matching the * with positional-only arguments and
the ** with keyword-only arguments.  In the example above though, I
don't really like how we look forward for ** but backward for *. I
feel like I the semantics should instead be::

- Everything after a * is a positional-only argument
- Everything after a ** is a keyword-only argument

These interpretations are consistent with the current meanings of
*args and **kwargs.

So to write the dict() or dict.update() signatures, we'd write::

    def update(*, self, container=None, **kwargs)

And to write the signature from my example, we'd write::

    def f(*, a, b=None, **, c=42, **kwargs)

My only use cases are for functions with '*' at the beginning, because
the only time I care about having positional only arguments is when I
also have a **kwargs, and in that situation, I want *all* other
arguments to be positional only.

Does anyone have a use case that requires both positional-only and
positional-or-keyword arguments?

STeVe
-- 
I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a
tiny blip on the distant coast of sanity.
        --- Bucky Katt, Get Fuzzy



More information about the Python-ideas mailing list