diff --git a/Utils.py b/Utils.py index 202b8da1..e4e94a45 100644 --- a/Utils.py +++ b/Utils.py @@ -114,6 +114,8 @@ def cache_self1(function: typing.Callable[[S, T], RetType]) -> typing.Callable[[ cache[arg] = res return res + wrap.__defaults__ = function.__defaults__ + return wrap diff --git a/test/utils/test_caches.py b/test/utils/test_caches.py index fc681611..b6db75c9 100644 --- a/test/utils/test_caches.py +++ b/test/utils/test_caches.py @@ -35,6 +35,19 @@ class TestCacheSelf1(unittest.TestCase): self.assertFalse(o1.func(1) is o1.func(2)) self.assertFalse(o1.func(1) is o2.func(1)) + def test_cache_default(self) -> None: + class Cls: + @cache_self1 + def func(self, _: Any = 1) -> object: + return object() + + o1 = Cls() + o2 = Cls() + self.assertIs(o1.func(), o1.func()) + self.assertIs(o1.func(1), o1.func()) + self.assertIsNot(o1.func(2), o1.func()) + self.assertIsNot(o1.func(), o2.func()) + def test_gc(self) -> None: # verify that we don't keep a global reference import gc