Author jaraco
Recipients jaraco, rhettinger
Date 2014-08-11.19:53:01
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1407786781.71.0.524022287452.issue22184@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2014-08-11 19:53:01jaracosetrecipients: + jaraco, rhettinger
2014-08-11 19:53:01jaracosetmessageid: <1407786781.71.0.524022287452.issue22184@psf.upfronthosting.co.za>
2014-08-11 19:53:01jaracolinkissue22184 messages
2014-08-11 19:53:01jaracocreate