Loading django/utils/functional.py +1 −0 Original line number Diff line number Diff line Loading @@ -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): Loading tests/utils_tests/test_functional.py +4 −0 Original line number Diff line number Diff line Loading @@ -50,6 +50,7 @@ class FunctionalTestCase(unittest.TestCase): @cached_property def value(self): """Here is the docstring...""" return 1, object() def other_value(self): Loading @@ -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 Loading Loading
django/utils/functional.py +1 −0 Original line number Diff line number Diff line Loading @@ -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): Loading
tests/utils_tests/test_functional.py +4 −0 Original line number Diff line number Diff line Loading @@ -50,6 +50,7 @@ class FunctionalTestCase(unittest.TestCase): @cached_property def value(self): """Here is the docstring...""" return 1, object() def other_value(self): Loading @@ -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 Loading