This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients rhettinger
Date 2011-10-19.22:06:35
SpamBayes Score 2.3839371e-08
Marked as misclassified No
Message-id <1319061996.92.0.980251015091.issue13227@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2011-10-19 22:06:36rhettingersetrecipients: + rhettinger
2011-10-19 22:06:36rhettingersetmessageid: <1319061996.92.0.980251015091.issue13227@psf.upfronthosting.co.za>
2011-10-19 22:06:36rhettingerlinkissue13227 messages
2011-10-19 22:06:36rhettingercreate