[New-bugs-announce] [issue13227] Option to make the lru_cache type specific

Raymond Hettinger report at bugs.python.org
Thu Oct 20 00:06:36 CEST 2011


New submission from Raymond Hettinger <raymond.hettinger at gmail.com>:

Based on a comment from Andrew Koenig, it is suggested that the lru_cache() offer an option to become type specific so that equal objects of different typed don't get cached to the same entry.

Here's an example:

@lru_cache(typed=True)
def square(x):
    print('squaring', x)
    return x * x

for x in [3, 3.0, 3, 3.0]:
    print(square(x))

Without type specificity, all four calls will return 9 rather than 9. 9.0, 9, 9.0.

First-pass patch attached.

----------
assignee: rhettinger
components: Library (Lib)
files: typed_lru.diff
keywords: patch
messages: 145976
nosy: rhettinger
priority: low
severity: normal
status: open
title: Option to make the lru_cache type specific
type: feature request
versions: Python 3.3
Added file: http://bugs.python.org/file23473/typed_lru.diff

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13227>
_______________________________________


More information about the New-bugs-announce mailing list