[Python-ideas] Syntax for late-binding of arguments [was: Default arguments ...]

Nick Coghlan ncoghlan at gmail.com
Fri May 15 16:33:20 CEST 2009

Steven D'Aprano wrote:
> On Fri, 15 May 2009 08:26:30 pm Nick Coghlan wrote:
>> Steven D'Aprano wrote:
>>> Some years ago, Python overloaded the binary operators * and ** for
>>> use as special markers in parameter lists. I suggest we could do
>>> the same, by overloading the & operator in a similar fashion:
>>> inside the parameter list, &x would mean to delay evaluation of the
>>> default argument:
> [...]
>> Marking the parameter name strikes me as wrong anyway - it's only the
>> evaluation of the default argument which is special, not the
>> parameter itself.
> But it is the parameter that is special. The default object itself is 
> not.

It's not the object that is being marked as special: it's the expression
to create the object. The new syntax is about delaying evaluation of
that expression - the parameter itself is perfectly normal, as is the
object that is ultimately bound to it. But moving the default argument
evaluation to call time instead of definition time - that's special.

It may be worth using something like "make_default()" in examples
instead of "[]" and see if that makes my point any clearer.

I doubt it's possible to come up with a concise syntax for this
(particularly one that plays well with function annotations), but best
of luck in the search :)


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-ideas mailing list