From 6ae230ff0d30eaebef2b3d42d8e3fdfc5b16ac6b Mon Sep 17 00:00:00 2001 From: cevans87 Date: Sun, 30 Jun 2019 21:19:08 -0700 Subject: [PATCH] Fixes memoize stripping __doc__ on decorated class --- atools/memoize_decorator.py | 2 +- setup.py | 2 +- test/test_memoize_decorator.py | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/atools/memoize_decorator.py b/atools/memoize_decorator.py index e757e35..76ac572 100644 --- a/atools/memoize_decorator.py +++ b/atools/memoize_decorator.py @@ -323,7 +323,7 @@ def __call__(cls, *args, **kwargs): class Wrapped(decoratee, metaclass=WrappedMeta): pass - return type(decoratee.__name__, (Wrapped,), {}) + return type(decoratee.__name__, (Wrapped,), {'__doc__': decoratee.__doc__}) @staticmethod def reset_all() -> None: diff --git a/setup.py b/setup.py index d029798..f16ecd7 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='atools', - version='0.6.1', + version='0.6.2', packages=['', 'atools'], python_requires='>=3.6', url='https://github.com/cevans87/atools', diff --git a/test/test_memoize_decorator.py b/test/test_memoize_decorator.py index 877f0a9..f4902e6 100644 --- a/test/test_memoize_decorator.py +++ b/test/test_memoize_decorator.py @@ -482,6 +482,14 @@ def foo(_: Foo) -> None: del f assert r() is None + def test_memoize_class_preserves_doc(self) -> None: + + @memoize + class Foo: + """Foo doc""" + + assert Foo.__doc__ == "Foo doc" + if __name__ == '__main__': unittest.main(verbosity=2)