On Tue, May 26, 2020 at 7:19 AM Ricky Teachey <ri...@teachey.org> wrote: > > This late binding is what I was clumsily referring to as option 3 (version > with no copying). But this is still going to end up having what people would > consider surprising behavior, is it not? > > It is essentially equivalent to this using current syntax: > > late_binder = lambda: [] > > def f(a = None): > if a is None: > a = late_binder() > > But if you have behavior like this (assuming the := syntax): > > _A = [] > def f(a:=_A): ... > > ...which is the same as this: > > _A = [] > def f(a=None): > if a is None: > a = _A > > Here's a little bit more fleshed out example: > > _complex_mutable_default = MyObj(a = 1, b = 2, c = 3, d = 4, e = 5, f = 6, g > = 7, h = 8, i = 9, j = 10) > > def func(x := _complex_mutable_default): ... > > Above, _complex_mutable_default is NOT immutable-- it is mutable. >
I don't see how this is going to be any different from anything else. If you do the same thing using the current "=object()" idiom, and you break out the complex default into a global, then obviously you're asking for it to be evaluated only once. Surely that shouldn't be at all surprising. ChrisA _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/XEBOHPDCOPLDWE2ICOTHTTAQHT7MXCPM/ Code of Conduct: http://python.org/psf/codeofconduct/