[New-bugs-announce] [issue43436] bounded _lru_cache_wrapprer behaves as if typed=True when it wasn't

Dan Snider report at bugs.python.org
Mon Mar 8 12:12:28 EST 2021


New submission from Dan Snider <mr.assume.away at gmail.com>:

Isn't the point of setting typed=True to make it so that e.g. True doesn't register as a hit when there is already a cache entry for 1.0? Assuming that is the case, although this report specifically targets 3.8 I found no indication that what I believe is the cause of this has been fixed in the interim.

def test():
    from functools import lru_cache
    class No1:
        __eq__ = 0 .__eq__
        __hash__ = 0 .__hash__
    class No2:
        __eq__ = (0,).__contains__
        def __hash__(self, /): return hash(0)
    @lru_cache(256, typed=False)
    def test(v): return [v]
    test(No1()), test(No1()), test(0.0), test(0)
    
    print(test.cache_info())
    @lru_cache(256, typed=False)
    def test(v): return [v]
    test(No2()), test(No2()), test(0.0), test(0)
    print(test.cache_info())


    CacheInfo(hits=0, misses=4, maxsize=256, currsize=4)
CacheInfo(hits=2, misses=2, maxsize=256, currsize=2)

----------
messages: 388271
nosy: bup
priority: normal
severity: normal
status: open
title: bounded _lru_cache_wrapprer behaves as if typed=True when it wasn't
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43436>
_______________________________________


More information about the New-bugs-announce mailing list