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 brilee
Recipients brilee
Date 2021-08-24.13:36:59
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1629812219.83.0.183087595287.issue44992@roundup.psfhosted.org>
In-reply-to
Content
This seems like unexpected behavior: Two keys that are equal and have equal hashes should yield cache hits, but they do not.


Python 3.9.6 (default, Aug 18 2021, 19:38:01) 
[GCC 7.5.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import functools
>>> 
>>> import numpy as np
>>> 
>>> @functools.lru_cache(maxsize=None)
... def f(x):
...   return x
... 
>>> py_str = 'hello world'
>>> np_str = np.str_(py_str)
>>> 
>>> assert py_str == np_str
>>> assert hash(py_str) == hash(np_str)
>>> 
>>> assert f.cache_info().currsize == 0
>>> f(py_str)
'hello world'
>>> assert f.cache_info().currsize == 1
>>> f(np_str)
'hello world'
>>> assert f.cache_info().currsize == 2
>>> print(f.cache_info())
CacheInfo(hits=0, misses=2, maxsize=None, currsize=2)
History
Date User Action Args
2021-08-24 13:36:59brileesetrecipients: + brilee
2021-08-24 13:36:59brileesetmessageid: <1629812219.83.0.183087595287.issue44992@roundup.psfhosted.org>
2021-08-24 13:36:59brileelinkissue44992 messages
2021-08-24 13:36:59brileecreate