On Sun, May 17, 2020 at 07:17:00PM -0000, James Lu wrote:
> Thus, only one of ":=" or "?=" should be adopted. They should be evalued on:
That does not logically follow. Even if we accept your idea that we
should have special syntax for late-binding of function defaults, and
that's not clear that we should, it does not follow that the only two
possible choices are `:=` and `?=`.
They might be your preferred choice, but that doesn't mean that "only
one of ... should be adopted". We could instead:
- choose something else;
- or choose nothing at all and stick to the status quo.
In any case, we should rule out `:=` of contention, because it already
has a meaning as the "walrus operator" for assignment expressions,
which makes it legal in function defaults:
def func(x=(a:=expression), y=a+1):
This is already valid in 3.8, so we should forget about overloading `:=`
with a second meaning.
> Do we want to encourage callers to pass None to indicate default
> arguments?
That isn't up to us, that's up the writer of the function being called.
There is a thirty year tradition of functions using None for default
arguments, that's not going to go away.
Neither are we going to force function writers to accept None as a
default. So the way functions can be called will depend partially on the
function itself, and partially on the caller's personal choice for how
they prefer to handle defaults.
> Since Python is a strongly typed language, it seems more consistent to me that
> this code should throw an error:
> def getoptions():
> ... # code to get options
> # whoops! missing return statement
> #return os.environ
Being strongly typed, or weakly typed, has nothing to do with return
statements. In Python, there is a 30 year tradition of being permitted
to leave out the return statement in functions or methods intended to be
used as "procedures" that operate by side-effect with no meaningful
return value.
We aren't going to break thousands of programs by making it an error to
leave out the return statement.
--
Steven
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/LY4M4PTXO4QKQXRJK2ZR3TYNWAJECZ4Z/
Code of Conduct: http://python.org/psf/codeofconduct/