[Python-ideas] Positional only arguments

Steven Bethard steven.bethard at gmail.com
Mon May 21 02:26:23 CEST 2007


On 5/20/07, George Sakkis <george.sakkis at gmail.com> wrote:
> On 5/20/07, Steven Bethard <steven.bethard at gmail.com> wrote:
>
> > 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?
[snip]
> For instance, think of a function that initially was designed to work
> for sequences and was defined as "def f(sequence, **kwds)". Later the
> implementor realizes that the same function works (or its
> implementation can easily change so that it works) for arbitrary
> iterables. It would be nice to go back and change the signature to
> "def f(iterable, **kwds)", knowing that nobody is calling it as
> f(sequence=range(10)).

This is a good example for why you might want positional-only
arguments.  But I guess I wasn't clear -- I'm looking for an example
where you need both a positional-only argument and a
positional-or-keyword argument *in the same signature*.

The reason I ask is that I'd like to propose that the lone * can only
appear at the beginning of the signature. That would cover the dict()
and dict.update() use cases as well as your use case above::

    def f(*, sequence, **kwds)

Are there any use cases that it wouldn't cover? Seems like the
cautious programmer from your example above would want all of his
positional arguments to be positional-only.

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