On 2021-10-26 10:55, Chris Angelico wrote:
>So why on earth NOT make these general "deferred" objects that can be used in 
other contexts?!
Because they're NOT deferred objects. They're argument defaults. Consider:

def f(x=>print("Hello")):
     ...

When should that print happen? Argument defaults are processed before
the function body begins, so you can be confident that it has happened
before the first line of actual code. But a deferred object might not
be evaluated until later, and in fact might not be evaluated at all.

I don't think that's necessarily true. If you have deferred objects, you could write some kind of decorator or class that evaluated deferred objects (or a particular kind of deferred object) when they occur as arguments.

You're speaking as if you think "deferred object" and "argument default" are mutually exclusive. But they're not. You could have an argument whose default value is a deferred object which is evaluated before the function body begins. Then it would be a default argument and a deferred object and would also be evaluated before the function body begins. The details would have to be worked out (just like they do for your PEP) but it's not automatically impossible.

--
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/XGXVJSQJK6QYN2GYM7HOREVFFFDCGS5M/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to