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

Larry Hastings larry at hastings.org
Wed Oct 9 15:51:13 CEST 2013


On 10/09/2013 07:48 AM, Eric Snow wrote:
> The PEP doesn't mention anything about inspect.Signature, which
> already supports positional-only parameters.  It should.

Well, inspect.Signature support for positional-only parameters is 
currently insufficient to express all of Python's builtins.  As I 
mentioned in my long reply to Benjamin just now, I got Brett to agree 
that I could add a "group" field to inspect.Parameter to indicate a 
positional parameter's "option group".  I guess this could be part of 
the PEP.


> This also has an impact on other Python implementations, where
> maintaining the same positional-only semantics for "builtins" is
> complicated (at least a little) by the lack of a positional-only
> syntax in Python.

Again, I don't expect this syntax to be implemented any time soon. But 
this does raise a mild sore point: Maciej and Armin Rigo tell me that 
PyPy's implementation of range() looks like this:

    def range(x, y=None, step=None):

The "None" above is not the Python None, it's RPython's internal None, 
so it's not available to Python programs.  But this does mean range() in 
PyPy accepts keyword parameters, and in fact this works:

    range(9, step=2)

That's way illegal in CPython.


> This is for the sake of only a couple unfortunate builtins, right?
> Parameter grouping will undoubtedly be the most controversial part of
> this PEP.  I'm not convinced this is a capability we need to encourage
> in any way.  Is there some alternate one-off we can use for range,
> addch, et al.?

I look forward to an alternate suggestion.  This is the least-bad thing 
I could come up with.


> What are the names bound to for unfulfilled optional groups?  Not
> bound (yuck)?  What is wrong with default values within optional
> groups (other than how messy the syntax starts to become)?

Please see my reply to Steven D'Aprano from about twelve hours ago.


> What about this:
>
> def spam([a,] b, [c,] d, /):

Quoting the PEP: "All "required" positional-only parameters must be 
contiguous."  b and d are discontinuous.  So this is illegal syntax.


//arry/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20131009/af137466/attachment-0001.html>


More information about the Python-Dev mailing list