[Python-ideas] Default arguments in Python - the return - running out of ideas but...
Terry Reedy
tjreedy at udel.edu
Thu May 14 01:08:50 CEST 2009
Bruce Leban wrote:
> Here's what I'd like:
>
> def myfunc(a, b, c = *lambda: expression):
> stuff
>
> The use of the lambda keyword here makes the scope of any variables in
> the expression clear. The use of the prefix * makes the syntax invalid
> today, suggests dereferencing and doesn't hide the overhead. This is
> equivalent to:
There is a proposal, which I thought was accepted in principle, to make
'* seq' valid generally, not just in arg-lists. to mean 'unpack the
sequence'. * (lambda:1,2)() would then be valid, and without the call,
would be a runtime, not syntax error.
Other than that ;0(, it would be an interesting idea.
> __unset = object()
> __default = lambda: expression
> def mfunc(a, b, c = __unset):
> if c == __unset:
> c = __default()
> stuff
tjr
More information about the Python-ideas
mailing list