New submission from Kaleb Barrett <dev.ktbarr...@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 <rep...@bugs.python.org> <https://bugs.python.org/issue42711> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com