On Thu, Dec 9, 2021 at 6:01 PM Christopher Barker <[email protected]> wrote:
>
>
>> My Option 1 (future statement, deprecation of early binding, and permanent
>> switch to late binding): +
>
>
> I have no authority about this at all, and a negligible amount of influence,
> but I’ve been around Python a long time:
>
> That is not going to happen.
>
> Way too much of a breaking change, and early bound defaults are useful, and
> awkward to replicate. It was not an accident.
>
I agree that it's a massively breaking change, but we could easily
have a system of early-bound defaults. Behold:
import functools
def lock_kwdefaults(**kw1):
def wrapper(f):
@functools.wraps(f)
def inner(*a, **kw2):
return f(*a, **{**kw2, **kw1})
return inner
return wrapper
@lock_kwdefaults(a=[])
def foo(val, a=>[], b=>[]):
a.append(val)
b.append(val)
print(a, b)
foo(1)
foo(2)
foo(3)
It would be an idiom no worse than we currently have. Either form can
implement the other form.
But there's no way we're going to do a complete migration to
late-bound. I'm definitely not advocating for that, and I highly doubt
the SC would approve any such proposal. (If nothing else, it would
impose a pointless run-time cost on all functions with defaults.)
ChrisA
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/D2CLQRK5DA7DGROJODHGEWHSVUDUN4YR/
Code of Conduct: http://python.org/psf/codeofconduct/