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 Федор Лянгузов
Recipients Федор Лянгузов
Date 2016-09-01.16:08:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1472746124.57.0.326377422927.issue27933@psf.upfronthosting.co.za>
In-reply-to
Content
Greetings,

I've encountered strange behavior when using functools.lru_cache as a function (not as a decorator): it is at least miscounting misses, but probably not work at all, when the result of functools.lru_cache()(func) is saved in variable other than 'func'. Consider this snippet:

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

f = functools.lru_cache()(factorial)
f(20)
print(f.cache_info())

Output should be: CacheInfo(hits=0, misses=21, maxsize=128, currsize=21)
Instead it is: CacheInfo(hits=0, misses=1, maxsize=128, currsize=1)

I'm using Python 3.5.2 64bit on Windows 7 Professional 64bit.
I've written 3 unittests (using built-in module), which are attached as a file. I don't know how to comment them (conceptually, not syntactically), sorry.

Fedor
History
Date User Action Args
2016-09-01 16:08:44Федор Лянгузовsetrecipients: + Федор Лянгузов
2016-09-01 16:08:44Федор Лянгузовsetmessageid: <1472746124.57.0.326377422927.issue27933@psf.upfronthosting.co.za>
2016-09-01 16:08:44Федор Лянгузовlinkissue27933 messages
2016-09-01 16:08:44Федор Лянгузовcreate