Jason R. Coombs <[email protected]> added the comment:
I've put together this full reproducer script:
```
import functools
def method_cache(method):
def wrapper(self, *args, **kwargs):
# it's the first call, replace the method with a cached, bound
method
bound_method = functools.partial(method, self)
cached_method = functools.lru_cache()(bound_method)
setattr(self, method.__name__, cached_method)
return cached_method(*args, **kwargs)
return wrapper
class MyClass:
calls = 0
@method_cache
def call_me_maybe(self, number):
self.calls += 1
return number
ob = MyClass()
ob.call_me_maybe(0)
ob.call_me_maybe(0)
assert ob.calls == 1
```
That code fails on Python 3.7.3. If I bypass the `from _functools import
_lru_cache_wrapper` in functools, the test no longer fails, so the issue seems
to be only with the C implementation.
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue36650>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com