Re: PEP 671 (late-bound arg defaults), next round of discussion!

Sorry, accidentally off-list. Here it is again. On Fri, Dec 10, 2021 at 4:50 PM Christopher Barker <pythonchb@gmail.com> wrote:
-- Christopher Barker, PhD (Chris) Python Language Consulting - Teaching - Scientific Software Development - Desktop GUI and Web Development - wxPython, numpy, scipy, Cython

And my response again, although slightly edited. On 12/11/2021 11:28 AM, Christopher Barker wrote:
I agree those are good questions. I think, like PEP 671, it would get evaluated at the start of the function (in this case, __init__). It's easier for dataclasses, because I could just force the evaluation there. But for normal function arguments, maybe we'd have to say that before the function starts executing, any arguments which are deferred objects automatically are evaluated. And I think the namespace would be where it's defined. I'll admit I haven't thought all of this through in enough detail to implement it. I'm just trying to point out that we could use the general concept in other places. One thing in particular I haven't thought through: what if you really want to pass in a "deferred object" to a function? Can you keep it from being evaluated? Would you specify that on the caller side, or the callee side?
I think it should be evaluated in the context of "fun". Clearly it would need to create a closure.
There are absolutely some issues that need thinking through. It's entirely possible the idea can't be made to work. I'm just saying we should think it through and see if it could be made to work before we just say "we only want late-bound things as function parameters, and we can't use them anywhere else". I'm worried that if we only do it for function parameters, we might need to change the syntax (and I guess possibly the semantics) in the future in order to support other uses for deferred objects.
That's an interesting idea. Eric

And my response again, although slightly edited. On 12/11/2021 11:28 AM, Christopher Barker wrote:
I agree those are good questions. I think, like PEP 671, it would get evaluated at the start of the function (in this case, __init__). It's easier for dataclasses, because I could just force the evaluation there. But for normal function arguments, maybe we'd have to say that before the function starts executing, any arguments which are deferred objects automatically are evaluated. And I think the namespace would be where it's defined. I'll admit I haven't thought all of this through in enough detail to implement it. I'm just trying to point out that we could use the general concept in other places. One thing in particular I haven't thought through: what if you really want to pass in a "deferred object" to a function? Can you keep it from being evaluated? Would you specify that on the caller side, or the callee side?
I think it should be evaluated in the context of "fun". Clearly it would need to create a closure.
There are absolutely some issues that need thinking through. It's entirely possible the idea can't be made to work. I'm just saying we should think it through and see if it could be made to work before we just say "we only want late-bound things as function parameters, and we can't use them anywhere else". I'm worried that if we only do it for function parameters, we might need to change the syntax (and I guess possibly the semantics) in the future in order to support other uses for deferred objects.
That's an interesting idea. Eric
participants (2)
-
Christopher Barker
-
Eric V. Smith