On Sat, 25 Jun 2022 at 00:54, Stephen J. Turnbull
<stephenjturnb...@gmail.com> wrote:
>
> David Mertz, Ph.D. writes:
> >>>>> On Fri, Jun 24, 2022 at 3:50 AM Stephen J. Turnbull 
> >>>>> <stephenjturnb...@gmail.com> wrote:
>
>  > > I'm suggesting modified semantics where deferreds can be a proxy
>  > > object, whose normal reaction to *any* operation (possibly
>  > > excepting name binding) is
>  > >
>  > > 1.  check for a memoized value,
>  > >     if not found evaluate its stored code, and memoize the value
>  > > 2.  perform the action on the memoized value
>  >
>  > I think I like these semantics better than those my draft proposal.  I
>  > haven't had a chance to enhance the proto-PEP more in the last few days
>  > (other work).  But all of these comments are extremely helpful, and I'll
>  > have a better version in a few days.  Hopefully I can address many of the
>  > concerns raised.
>
> We (not sure how much help I'll be, but I'm in) need to deal with
> Chris A's point that a pure memoizing object doesn't help with the
> mutable defaults problem.  That is with
>
>     def foo(cookiejar=defer []):
>
> foo() produces a late bound empty list that will be used again the
> next time foo() is invoked.
>
> Now, we could modify the defer syntax in function parameter default
> values to produce a deferred deferred object (or, more likely, a
> deferred object that lacks the memoization functionality).  But I
> suspect Chris will respond with (a polite expression with the
> semantics of) the puke emoji, and I'm not sure I disagree, yet. ;-)

It can't simply lack the memoization functionality, as that would
break the obvious expectation that the list is the same throughout the
function:

def foo(cookiejar=defer []):
    cookiejar.append(1) # new list here
    cookiejar.append(2) # another new list???

So the only way around it would be to make the defer keyword somehow
magical when used in a function signature, which kinda defeats the
whole point about being able to reuse another mechanic to achieve
this. Also, it would create some other oddity, depending on which way
this is handled:

_default = defer []
def foo(cookiejar=_default):

Does this also get the magic, or doesn't it? Either way, there'd be a
really weird inconsistency here.

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

Reply via email to