[Python-ideas] Optional parameters without default value

Todd toddrjen at gmail.com
Fri Mar 10 18:06:40 EST 2017


On Mar 10, 2017 02:42, "Terry Reedy" <tjreedy at udel.edu> wrote:

On 3/2/2017 3:03 AM, Serhiy Storchaka wrote:

> Function implemented in Python can have optional parameters with default
> value. It also can accept arbitrary number of positional and keyword
> arguments if use var-positional or var-keyword parameters (*args and
> **kwargs).
>

In other words, Python signature possibilities are already unusually
complex.


But there is no way to declare an optional parameter that
> don't have default value.
>
... [moving the following up]

> I propose to add a new syntax for optional parameters. If the argument
> corresponding to the optional parameter without default value is not
> specified, the parameter takes no value.

-1

Being able to do this would violate what I believe is the fundamental
precondition for python-coded function bodies: all parameters are bound to
an object (so that using a parameter name is never a NameError); all
arguments are used exactly once in the binding process; the binding is done
without ambiguity (or resort to disambiguation rules).  Calls that prevent
establishment of this precondition result in an exception.

This precondition is normal in computing languages.  I believe that all of
the ~20 languages I have used over decades have had it.  In any case, I
believe it is important in understanding Python signatures and calls, and
that there would need to be a strong reason to alter this precondition.
(Stronger than I judge the one given here to be.)


-1 also

Having used a language extensively that does not enforce this precondition
(MATLAB), I agree that not being able count on arguments existing makes
handing function arguments much more difficult.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170310/3ab64fe7/attachment.html>


More information about the Python-ideas mailing list