[issue39554] @functools.lru_cache() not respecting typed=False

Raymond Hettinger report at bugs.python.org
Tue Feb 4 23:18:33 EST 2020


Raymond Hettinger <raymond.hettinger at gmail.com> added the comment:

I understand the confusion, but this isn't a bug.

Specifying "typed=True" means that the cache is required to treat the calls f(1) and f(1.0) as distinct.

However, specifying or defaulting to "typed=False" means that the cache isn't required to do so, but it is still allowed to.

This flexibility allowed the tool to add a space saving path for *int*.  It comes at the expense of leaving equivalent int/float calls as distinct.  Most apps win here because it is typical to keep the type the same across calls.  Also, the saved space may allow users to choose a larger value for *maxsize*.

Note, similar liberties were taken with keyword argument ordering.  Formerly, f(a=1, b=2) was considered equivalent to f(b=1, a=1).  Now, they are treated as distinct.  The downside is a potential extra call.  The upside is that we save the huge overhead of sorting the keyword arguments.  Mostly, this is a net win, despite the visible change in cache utilization statistics.

----------
nosy: +rhettinger
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

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


More information about the Python-bugs-list mailing list