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

Steven D'Aprano steve at pearwood.info
Thu Oct 10 01:02:02 CEST 2013


On Wed, Oct 09, 2013 at 04:15:36PM +0200, Larry Hastings wrote:

>- parameters in optional groups should just have an implied "=None" >that can be overriden if desired. >

No no no! You can't have a default value, and you definitely couldn't use None. range() decides what its arguments mean based on how many arguments it receives. If I understand your proposal correctly, you suggest that range(None, 5) would return the same result as range(5) But that's simply not how it works.

Hmmm... I'm not entirely sure that I understand, but let me see if I've got it.

range is defined something like this, only in C:

def range(*args): if len(args) == 1: start, stop, step = 0, args[0], 1 elif len(args) == 2: start, stop, step = args[0], args[1], 1 elif len(args) == 3: start, stop, step = args else: raise TypeError ...

So we can't document range as having the signature:

range(start=None, stop, range=None)

(modulo choice of defaults). Even if some future implementation of positional-only arguments allowed functions to set defaults, you would still have to deal with cases like range that don't.

Do I understand you correctly?

If so, then I ask that this PEP should not rule out setting defaults in the the future, but make it clear that even if defaults are allowed, there needs to be some way to handle defaultless-but-still-optional arguments, for cases like range.

-- Steven



More information about the Python-Dev mailing list