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

George Sakkis george.sakkis at gmail.com
Sun May 10 19:00:15 CEST 2009


On Sun, May 10, 2009 at 12:10 PM, Arnaud Delobelle
<arnodel at googlemail.com> wrote:

> Furthemore, by removing default arguments from the language, we can let
> people choose what semantics they want for default arguments.  I.e, if they
> want them to be reevaluated each time, they could write the default
> decorator as follows (it is exactly the same as the one above except for a
> pair of parentheses that have been added on one line.

Cute, but that's still a subset of what the dynamic semantics would
provide; the evaluated thunks would have access to the previously
defined arguments:

def foo(a, b, d=(a*a+b+b)**0.5, s=1/d):
    return (a,b,d,s)

would be equivalent to

missing = object()
def foo(a, b, d=missing, s=missing):
    if d is missing:
        d = (a*a+b+b)**0.5
    if s is missing:
        s = 1/d
    return (a,b,d,s)

George



More information about the Python-ideas mailing list