[Python-ideas] from __future__ import runtime_default_kwargs
Steven D'Aprano
steve at pearwood.info
Mon Mar 11 07:58:17 EDT 2019
Hi James,
Some weeks ago, you started a discussion here about "Clearer
Communication". Here's another suggestion to help: don't expect your
readers to either guess, or infer from the code, what your proposal
means. As the Zen of Python says:
Explicit is better than implicit.
Looking at your sample code, I'm guessing that you want support for late
binding of function parameter defaults. Python uses early binding, see
the FAQs:
https://docs.python.org/3/faq/programming.html#why-are-default-values-shared-between-objects
Am I correct? If not, can you please explain what it is that you are
actually suggesting.
Note that early binding is not a bug to be fixed, it is a design choice
which is sometimes useful and sometimes not useful. Mutable defaults
being shared is sometimes a good feature to have, and for immutable
defaults, early binding is more efficient.
I don't think that changing the behaviour will be acceptible, I know I
would argue strongly in favour of keeping early binding.
(If the language defaults to early binding, it is easy to implement late
binding in the body of the function; but if the language uses late
binding, it is difficult and annoying to get early binding when you want
it. We should stick to the status quo.)
But having a nice, clean way to get late binding semantics as an
alternative might be acceptible, if we can agree on acceptible syntax
and a mechanism.
--
Steven
More information about the Python-ideas
mailing list