[issue40504] Restore weakref support for lru_cache wrappers

Dennis Sweeney report at bugs.python.org
Mon May 4 19:35:18 EDT 2020


Dennis Sweeney <sweeney.dennis650 at gmail.com> added the comment:

I can submit a PR. Just making sure I understand, is this essentially the desired behavior change?

import weakref
import functools

if 0:
    from test.support import import_fresh_module
    functools = import_fresh_module('functools', blocked=['_functools'])

@functools.lru_cache
def f(x):
    return x

ref_to_f = weakref.ref(f)
print(ref_to_f)

# Current:
# TypeError: cannot create weak reference to 'functools._lru_cache_wrapper' object
# Desired:
# <weakref at 0x000001ABFE0F5090; to 'function' at 0x000001ABFE2D5AF0 (f)>

----------
nosy: +Dennis Sweeney

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


More information about the Python-bugs-list mailing list