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

Terry Reedy tjreedy at udel.edu
Wed Oct 9 20:25:18 CEST 2013


On 10/9/2013 1:05 PM, Larry Hastings wrote:

> First, if you're proposing to change the signature of range()... well,
> good luck.  Any proposals I made like that got shot down almost
> immediately.  I /think/ Guido said somewhere "range isn't changing.
> deal with it.", though I admit I don't have a reference for that handy.

I am sure that he has rejected any backward-incompatible change, as 
would I. Allowing keyword passing *is* compatible, so I would not guess 
about that.

> Also, if you're suggesting "change the semantics of builtins to get rid
> of positional-only parameters",

Georg, and I agree, said *most*.

> I've got a different example for you: the dict constructor,
 > which /must/ accept a single optional positional-only parameter.

An *optional* positional-only parameter can be and sometimes is or has 
been denoted by [], as with dir([object]).  In Python 3, [] is no longer 
used for normal optional params, which always have defaults. The dict 
signature could be (and maybe once was) given as 
dict([mapping-or-iterable], *kwds).

There is a definite problem, though with required positional-only 
params. If these are rarer than at present, then it may matter less to 
people the indicator is. If they think it obnoxious, they will not have 
to see it so often,

Unlike Georg, I think '/' is plausibly ok. You should, however, 
explicitly say in the PEP that it was selected not randomly but by rough 
analogy. Division (/) is the inverse of multiplication (*), and 
positional-only is sort of the 'inverse' of keyword-only. (If I am 
wrong, and the above is just an accident, it is at least a way to 
remember ;-).

Another approach would be to make parameter names that are illegal to 
use in calls illegal as Python names. "form follows function" or in this 
case, "bad form indicates no function". For instance, always put a 
*hyphen* in the displayed parameter name, as I intentionally did above. 
If nothing else, add a '-p' suffix. A hyphen is not legal in a name, so 
'object-p', for instance, cannot possibly be used to make a call such as:
 >>> dir(object-p=int)
SyntaxError: keyword can't be an expression

Note that I am talking about the doc and help results, not necessarily 
about the CPython C code most people never see.

-- 
Terry Jan Reedy



More information about the Python-Dev mailing list