diff --git a/django/utils/functional.py b/django/utils/functional.py index 9d8ecf6856b..ceb8b050559 100644 --- a/django/utils/functional.py +++ b/django/utils/functional.py @@ -51,6 +51,7 @@ class cached_property(object): """ def __init__(self, func, name=None): self.func = func + self.__doc__ = getattr(func, '__doc__') self.name = name or func.__name__ def __get__(self, instance, type=None): diff --git a/tests/utils_tests/test_functional.py b/tests/utils_tests/test_functional.py index e9010b31355..b806be0b167 100644 --- a/tests/utils_tests/test_functional.py +++ b/tests/utils_tests/test_functional.py @@ -50,6 +50,7 @@ class FunctionalTestCase(unittest.TestCase): @cached_property def value(self): + """Here is the docstring...""" return 1, object() def other_value(self): @@ -57,6 +58,9 @@ class FunctionalTestCase(unittest.TestCase): other = cached_property(other_value, name='other') + # docstring should be preserved + self.assertEqual(A.value.__doc__, "Here is the docstring...") + a = A() # check that it is cached