On Mon, Oct 25, 2021 at 12:47 AM David Mertz, Ph.D.
<david.me...@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
_______________________________________________
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/BMKPZ7FTIVXE6NVDM2ZS6IB6RWZKATG2/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to