[Python-ideas] PEP 572: Statement-Local Name Bindings

Chris Angelico rosuav at gmail.com
Wed Feb 28 03:37:20 EST 2018


On Wed, Feb 28, 2018 at 6:46 PM, Matt Arcidy <marcidy at gmail.com> wrote:
> I have been struggling to justify the need based on what I have read.  I
> hope this isn't a dupe, I only saw caching mentioned in passing.
>
> Also please excuse some of the naive generalizations below for illustrative
> purposes.
>
> Is there a reason memoization doesn't work? If f is truly expensive, using
> this syntax only makes sense if you have few comprehensions (as opposed to
> many iterations) and few other calls to f. Calling f in 10 comprehensions
> would (naively) benefit from memoization more than this.  It appears to me
> to be ad-hoc memoization with limited scope.  is this a fair statement?

Memoization is only an option if the expression in question is (a) a
single cacheable function call, and (b) used twice without any
variation. If it's any sort of more complicated expression, that
concept doesn't work.

ChrisA


More information about the Python-ideas mailing list