This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author steven.daprano
Recipients ncoghlan, rhettinger, steven.daprano, Федор Лянгузов
Date 2016-09-01.16:35:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1472747753.43.0.0996727547652.issue27933@psf.upfronthosting.co.za>
In-reply-to
Content
This behaviour is expected. The factorial function calls itself, it doesn't call "f", but it is "f" which has the cache. So the call to f() goes through the cache, misses, and then calls factorial(), which has no cache.

In effect, what you have written is something like:

def factorial(n):
    if n == 0:
        return 1
    else:
        return n * factorial(n-1)

def f(n):
    if n in f.cache:
        return f.cache[n]
    else:
        x = f.cache[n] = factorial(n)
        return x

f.cache = lru_cache()
History
Date User Action Args
2016-09-01 16:35:53steven.dapranosetrecipients: + steven.daprano, rhettinger, ncoghlan, Федор Лянгузов
2016-09-01 16:35:53steven.dapranosetmessageid: <1472747753.43.0.0996727547652.issue27933@psf.upfronthosting.co.za>
2016-09-01 16:35:53steven.dapranolinkissue27933 messages
2016-09-01 16:35:53steven.dapranocreate