[Python-Dev] PEP 457: Syntax For Positional-Only Parameters (original) (raw)

Eric Snow ericsnowcurrently at gmail.com
Wed Oct 9 20:20:28 CEST 2013


On Wed, Oct 9, 2013 at 8:53 AM, Larry Hastings <larry at hastings.org> wrote:

But that's not how addch works. addch counts how many arguments it received; if it is called with one or two, it does one thing, and if it's called with three or four it does something else. You can't duplicate these semantics with

Similarly, you can't accurately express the semantics of range's arguments using default values. PyPy's approach is approximately like this: def range(x, y=None, step=None): step = 1 if step is None else step if y is not None: start, stop = x, y else: start, stop = 0, x But now introspection information on range() is inaccurate and unhelpful. (Not to mention, they allow specifying step without specifying y, by using keyword arguments.) My goal in writing the PEP was to codify existing practice, which meant reflecting these (annoying!) corner cases accurately.

The optional group syntax is in the PEP to support a small number of builtin functions, right? Is it just range() and addch()? If so, adding the complexity of optional groups (as syntax) isn't worth it. I'm still +0 on adding positional-only arguments (with '/').

As others have said, you can already achieve all this using *args. 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.

As far as documentation goes, I'll defer to Georg and other "Doc/library"-savvy folks about the downside of using the syntax in this PEP. However, I agree it would be nice to be able to indicate in the docs that a parameter is positional-only. Perhaps it is as simple as always listing the positional-only parameters right after the signature. For example:

type(object) type(name, bases, dict) positional-only: object, name, bases, dict

With one argument, return the type of ...

range(stop) range(start, stop, step) positional-only: start, stop, step

Rather than being a function, ...

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.

-eric



More information about the Python-Dev mailing list