Pascal Chambon wrote:
Without new keyword or operator, a good looking solution for dynamic defaults is unlikely to appear, imo.
I could content myself of the proposed solution : @dynamic def func (a, b = lambda : ): pass But I just dislike the fact that the "dynamic" applies to all the defaults, even those which weren't supposed to be dynamic (and writing "lambda : lambda : ") doesn't look good). Would there be any way of separating "to-be-called" lambdas from normal ones ? Except with a syntax like "b = dyn(lambda: )" ?
Use function annotations.
def f(a: dynamic.override=list, b=1): pass
(<class 'list'>, 1)
Just make a decorator that looks in the annotations to figure out what to replace and what to leave be.
Also "lambda: " is clearly inferior to "list".