Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lrucache should reject maxsize as a function #66380

Closed
jaraco opened this issue Aug 11, 2014 · 4 comments
Closed

lrucache should reject maxsize as a function #66380

jaraco opened this issue Aug 11, 2014 · 4 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@jaraco
Copy link
Member

jaraco commented Aug 11, 2014

BPO 22184
Nosy @rhettinger, @jaraco, @jwilk, @serhiy-storchaka
Files
  • lru.diff: Add type check for maxsize
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/rhettinger'
    closed_at = <Date 2014-08-12.19:46:12.034>
    created_at = <Date 2014-08-11.19:53:01.665>
    labels = ['type-bug', 'library']
    title = 'lrucache should reject maxsize as a function'
    updated_at = <Date 2014-08-13.04:59:43.682>
    user = 'https://github.com/jaraco'

    bugs.python.org fields:

    activity = <Date 2014-08-13.04:59:43.682>
    actor = 'rhettinger'
    assignee = 'rhettinger'
    closed = True
    closed_date = <Date 2014-08-12.19:46:12.034>
    closer = 'rhettinger'
    components = ['Library (Lib)']
    creation = <Date 2014-08-11.19:53:01.665>
    creator = 'jaraco'
    dependencies = []
    files = ['36355']
    hgrepos = []
    issue_num = 22184
    keywords = ['patch']
    message_count = 4.0
    messages = ['225202', '225241', '225251', '225254']
    nosy_count = 5.0
    nosy_names = ['rhettinger', 'jaraco', 'jwilk', 'python-dev', 'serhiy.storchaka']
    pr_nums = []
    priority = 'low'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue22184'
    versions = ['Python 3.4', 'Python 3.5']

    @jaraco
    Copy link
    Member Author

    jaraco commented Aug 11, 2014

    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.

    @jaraco jaraco added the stdlib Python modules in the Lib dir label Aug 11, 2014
    @rhettinger rhettinger self-assigned this Aug 12, 2014
    @rhettinger rhettinger added the type-bug An unexpected behavior, bug, or error label Aug 12, 2014
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Aug 12, 2014

    New changeset 780693490c84 by Raymond Hettinger in branch '3.4':
    bpo-22184: Early detection and reporting of missing lru_cache parameters
    http://hg.python.org/cpython/rev/780693490c84

    @jaraco
    Copy link
    Member Author

    jaraco commented Aug 13, 2014

    Awesome. Thanks for the quick implementation.

    @rhettinger
    Copy link
    Contributor

    Awesome. Thanks for the quick implementation.

    Happy to do it. Thanks for the clean bug report.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants