Late-binding of function defaults (was Re: What is a function parameter =[] for?)

Chris Angelico rosuav at gmail.com
Sat Nov 21 12:02:13 EST 2015


On Sun, Nov 22, 2015 at 2:01 AM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
>> and then the decorator could wrap the function. I'm not entirely sure
>> I could implement it reliably, but even leaving that aside, having to
>> put "lambda:" in front of everything is pretty ugly.
>
> Note that "lambda: []" can also be spelled "list".

In that particular example, yes. I kept it in the large form to
maintain the parallel with the version I was quoting. But if the
decorator were to be written, it would probably be something along the
lines of "if the default is callable, do the late-binding magic", so
'list' would work just fine.

ChrisA



More information about the Python-list mailing list