New submission from Raymond Hettinger <[email protected]>:
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 <[email protected]>
<http://bugs.python.org/issue13227>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com