Skip to content
Snippets Groups Projects
Commit c7addcf7 authored by Markus Holzer's avatar Markus Holzer
Browse files

Merge branch 'fix_sharedmethodcache_docstrings' into 'master'

Fix: sharedmethodcache didn't preserve docstrings

See merge request pycodegen/pystencils!287
parents 1f3b1300 b1dccb49
Branches
Tags
1 merge request!287Fix: sharedmethodcache didn't preserve docstrings
Pipeline #38703 passed
import os
from collections.abc import Hashable
from functools import partial
from functools import partial, wraps
from itertools import chain
try:
......@@ -43,6 +43,7 @@ def sharedmethodcache(cache_id: str):
Of course, for this to be useful, said methods must have the same signature (up to additional kwargs)
and must return the same result when called with the same arguments."""
def _decorator(user_method):
@wraps(user_method)
def _decorated_func(self, *args, **kwargs):
objdict = self.__dict__
cache = objdict.setdefault(cache_id, dict())
......
......@@ -60,13 +60,16 @@ class Triad:
@sharedmethodcache("triad_cache")
def triad(self, a, b, c=0):
"""Computes the triad a*b+c."""
self.triad_called += 1
return a * b + c
def test_triab_memoization():
def test_triad_memoization():
triad = Triad()
assert triad.triad.__doc__ == "Computes the triad a*b+c."
t = triad.triad(12, 4, 15)
assert triad.triad_called == 1
assert triad.triad_cache[(12, 4, 15)] == t
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment