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

Jim Jewett jimjjewett at gmail.com
Fri May 15 16:49:42 CEST 2009


On 5/15/09, Nick Coghlan <ncoghlan at gmail.com> wrote:

> 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 :)

I think this is inching towards the variable-defining keywords, like
once, final, static ...

This one might be "late" or "lazy", though "new" would work if you
kept it only to function definitions.

    def f(     a=make_default_once(),
          lazy b=make_default_each_time()): ...

    VAR_IN_MODULE_API = lazy whoops_wanted_a_property_after_all()

-jJ



More information about the Python-ideas mailing list