[Python-ideas] Default arguments in Python - the return

George Sakkis george.sakkis at gmail.com
Sun May 10 08:32:07 CEST 2009


On Sun, May 10, 2009 at 1:28 AM, Scott David Daniels
<Scott.Daniels at acm.org> wrote:
>
> Any argument for changing to a more "dynamic" default scheme had better
> have a definition of the behavior of the following code, and produce a
> good rationale for that behavior:
>
>    x = 5
>    def function_producer(y):
>        def inner(arg=x+y):
>            return arg + 2
>        return inner

I don't think the proposed scheme was ever accused of not being
well-defined. Here's the current equivalent dynamic version:

    x = 5
    def function_producer(y):
        missing = object()
        def inner(arg=missing):
            if arg is missing:
                arg = x+y
            return arg + 2
        return inner

-1 for changing the current semantics (too much potential breakage),
+0.x for a new keyword that adds dynamic semantics (and removes the
need for the sentinel kludge).

George



More information about the Python-ideas mailing list