Steven D'Aprano added the comment:

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()

----------
nosy: +steven.daprano

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue27933>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to