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

Scott David Daniels Scott.Daniels at Acm.Org
Sun May 10 20:30:49 CEST 2009


George Sakkis wrote:
> 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

So sorry.

      def function_producer(y):
          def inner(arg=x+y):
              return arg + 2
          y *= 10
          return inner

I was trying to point out that it becomes much trickier building
functions with dynamic parts, and fluffed the example.

--Scott David Daniels
Scott.Daniels at Acm.Org




More information about the Python-ideas mailing list