
On Mon, Oct 25, 2021 at 12:47 AM David Mertz, Ph.D. <david.mertz@gmail.com> wrote:
On Sun, Oct 24, 2021, 12:20 AM Chris Angelico
How would it know to look for a and b inside fn2's scope, instead of looking for x inside fn2's scope?
The same way 'eval("a+b")' knows to look in the local scope when evaluated.
I mean, of course 'x' could be rebound in some scope before it was evaluated. But a "deferred" object itself would simply represent potential computation that may or may not be performed.
If we wanted to use descriptors, and e.g. use 'x.val' rather than plain 'x' , we could do it now with descriptors. But not with plain variable names now.
Not sure I understand. Your example was something like: def fn2(thing): a, b = 13, 21 x = 5 print("Thing is:", thing) def f(x=defer: a + b): a, b = 3, 5 fn2(defer: x) return x So inside f(), "defer: a + b" will look in f's scope and use the variables a and b from there, but passing a "defer: x" to fn2 will use x from f's scope, and then a and b from fn2's? ChrisA