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

Georg Brandl g.brandl at gmx.net
Wed Oct 9 17:09:47 CEST 2013


Am 09.10.2013 16:53, schrieb Larry Hastings:
> On 10/09/2013 04:26 PM, Georg Brandl wrote:
>>> I realize you are -1 on the proposal in general, but I'd be very interested if
>>> you could propose an alternate approach where I didn't need "a new spelling for
>>> None" as you put it.
>> I think I would make Steven's proposed syntax mandatory: let the implementor
>> of the function decide which value stands for "not given" -- just like we do
>> in the C version, BTW.
> 
> 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

Well, why should a function that requires counting arguments even in C code
not be implemented using *args?

Documentation can cope fine, in the case of range() with two signatures.

> 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.

These are only two, one of them being exceedingly obscure.  The hobgoblin
comes to mind :)

cheers,
Georg



More information about the Python-Dev mailing list