[Python-ideas] Optional parameters without default value

Paul Moore p.f.moore at gmail.com
Thu Mar 2 07:20:23 EST 2017


On 2 March 2017 at 11:31, Stephan Houben <stephanh42 at gmail.com> wrote:
> NoDefault would be special syntax so that this would be disallowed:
>
> f(NoDefault)

I think the key point of confusion here is whether the language needs
to enforce this or it's just convention.

MAL is saying that f(NoDefault) is disallowed - but not that the
language will somehow notice what you've done and refuse to let you,
just that you mustn't do it or your program will be wrong. Stephan
seems to be saying that you'd get a SyntaxError (or a RuntimeError?
I'm not sure when you'd expect this to be detected - consider
f(*[NoDefault])) if you wrote that.

Philosophically, Python has always tended in the past towards a
"consenting adults" rule - so we don't reject code like this but
expect people to use the constructs given in the way they were
intended.

The OP's proposal is about making it more convenient to specify that
parameters are "positional only", by avoiding the need to create
custom sentinels (or agree on a common conventional value). That seems
to me to be a reasonable proposal - typical sentinel handling code is
fairly verbose. OTOH, creating a language mandated sentinel does
nothing to improve readability (all we gain is omission of the
creation of a custom sentinel) and has the downside that we add yet
another special value to the language, that provides a subtly
different meaning of "not present" than the ones we have.

So I guess I'm +0.5 on the proposed "positional only parameters"
syntax, and -1 on any form of new language-defined sentinel value.

Paul


More information about the Python-ideas mailing list