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:

    @lrucache
    def expensive(param):
        pass

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

    for x in range(10000):
        expensive(x)

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 <rep...@bugs.python.org>
<http://bugs.python.org/issue22184>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to