[New-bugs-announce] [issue42711] lru_cache and NotImplemented

Kaleb Barrett report at bugs.python.org
Tue Dec 22 01:40:07 EST 2020


New submission from Kaleb Barrett <dev.ktbarrett at gmail.com>:

Having to return `NotImplemented` (which counts as a successful function call) in `functools.lru_cache` and `functools.cache` decorated binary dunder methods has the potential to fill the LRU cache with calls that will in ultimately result in errors (read "garbage").

There are a few ways to avoid this IMO:

1. Change `functools.lru_cache` not cache calls that result in `NotImplemented`.
2. Allow a user to easily extend `functools.lru_cache` (the implementation is not extensible right now) to do the previously mentioned operation.
3. Add the ability to *throw* `NotImplemented` in binary dunder methods so the function call does not complete. This would work exactly like returning `NotImplemented` and be handled by the runtime.

And my current solution...

4. Copy-paste `functools.lru_cache` and add in changes for solution 1 :)

----------
components: Library (Lib)
messages: 383573
nosy: ktbarrett
priority: normal
severity: normal
status: open
title: lru_cache and NotImplemented
type: performance
versions: Python 3.10, Python 3.6, Python 3.7, Python 3.8, Python 3.9

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


More information about the New-bugs-announce mailing list