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
import os
from import Hashable
from functools import partial
from functools import partial, wraps
from itertools import chain
......@@ -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):
def _decorated_func(self, *args, **kwargs):
objdict = self.__dict__
cache = objdict.setdefault(cache_id, dict())
......@@ -60,13 +60,16 @@ class Triad:
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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment