[New-bugs-announce] [issue22184] lrucache should reject maxsize as a function

Jason R. Coombs report at bugs.python.org
Mon Aug 11 21:53:01 CEST 2014

New submission from Jason R. Coombs:

In https://bitbucket.org/jaraco/backports.functools_lru_cache/issue/1/python-2-attributeerror-int-object-has-no, a user was confused when he tried to use the lrucache decorator incorrectly, passing the wrapped function directly to lrucache. Consider:

    def expensive(param):

One can even get away with profiling that now decorated function:

    for x in range(10000):

The test will run without error, but it's not doing what the user thinks it's doing. In the first section, it's creating a decorator, and in the second section, it's wrapping an int in that decorator, but because the wrapper is never called, an error is never raised.

I propose adding a simple check that if maxsize is callable, raise a TypeError. That would prevent unintentional misuse and subtle non-failure with minimal impact on performance.

components: Library (Lib)
messages: 225202
nosy: jason.coombs, rhettinger
priority: normal
severity: normal
status: open
title: lrucache should reject maxsize as a function

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list