[Python-Dev] PEP 457: Syntax For Positional-Only Parameters

Eric Snow ericsnowcurrently at gmail.com
Thu Oct 10 00:38:39 CEST 2013


On Wed, Oct 9, 2013 at 12:20 PM, Eric Snow <ericsnowcurrently at gmail.com> wrote:
> For me the allure of positional-only arguments lies in the following:
>
> 1. not having to roll my own *args handling;
> 2. not having to clutter up my code with the *args handling;
> 3. not having to handle positional-or-keyword params with *args when
> also using positional-only args;
> 4. documentation and help() can be more clear/accurate.
>
> [snip]
>
> Regarding help(), getting pydoc to make use of inspect.Signature
> objects would be great.  The idea of supporting optional groups in
> inspect.Parameter sounds good to me and pydoc could make use of that.

It may work better to facilitate the syntax in this PEP through
inspect.Signature and friends, rather than as a pseudo-addition to the
Python syntax.  Here is some additional API that could help:

* inspect.Signature.from_string(sig) - a factory that parses a
signature string (including "/" from this PEP or perhaps "<param>").
Could Argument Clinic make use of this directly?
* inspect.Signature.__str__() - updated to also display "/" for
positional-only (or the "<param>" syntax that RDM described).
* inspect.MultiSignature - a Sequence(?) containing one or more
Signature objects (proxies the first one), which facilitates grouping.
* inspect.MultiSignature.from_string(sig) - a factory that parses a
signature string (including the full syntax from this PEP), adding a
Signature for each derivable signature.

These, along with a few other additions, would certainly help address
the 4 things I listed above.  I have a rough implementation of the
above APIs (ignore anything else :) [1].

-eric

[1] https://bitbucket.org/ericsnowcurrently/odds_and_ends/src/default/signature.py


More information about the Python-Dev mailing list