On 2021-12-05 08:14, Chris Angelico wrote:
Closures cannot be executed without a context. Consider:

def f(x=lambda: (a:=[])):
     if isinstance(x, FunctionType): x = x()
     print(a)

Here's the problem: The name 'a' should be in the context of f, but
that context*does not exist*  until f starts executing.

Frankly, I would consider this another disadvantage of late-bound arguments as defined under your proposal. I do not want argument defaults to be able to have the side effect of creating additional local variables in the function. (There is also the question of whether they could assign in this manner to names already used by other arguments, so that one argument's default could potentially override the default of another.)

--
Brendan Barnwell
"Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail."
   --author unknown
_______________________________________________
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/TZACNAPKH3T6QVH4RPPXSAH2SFAGG4QD/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to