self.func = func
self.attrname = None
self.__doc__ = func.__doc__
+ self.__module__ = func.__module__
def __set_name__(self, owner, name):
if self.attrname is None:
"""
return cls.a_class_attribute
+ @functools.cached_property
+ def a_cached_property(self):
+ """
+ >>> print(SampleClass(29).get())
+ 29
+ """
+ return "hello"
+
class NestedClass:
"""
>>> x = SampleClass.NestedClass(5)
3 SampleClass.NestedClass
1 SampleClass.NestedClass.__init__
1 SampleClass.__init__
+ 1 SampleClass.a_cached_property
2 SampleClass.a_classmethod
1 SampleClass.a_classmethod_property
1 SampleClass.a_property
3 some_module.SampleClass.NestedClass
1 some_module.SampleClass.NestedClass.__init__
1 some_module.SampleClass.__init__
+ 1 some_module.SampleClass.a_cached_property
2 some_module.SampleClass.a_classmethod
1 some_module.SampleClass.a_classmethod_property
1 some_module.SampleClass.a_property
3 SampleClass.NestedClass
1 SampleClass.NestedClass.__init__
1 SampleClass.__init__
+ 1 SampleClass.a_cached_property
2 SampleClass.a_classmethod
1 SampleClass.a_classmethod_property
1 SampleClass.a_property
0 SampleClass.NestedClass.get
0 SampleClass.NestedClass.square
1 SampleClass.__init__
+ 1 SampleClass.a_cached_property
2 SampleClass.a_classmethod
1 SampleClass.a_classmethod_property
1 SampleClass.a_property
def test_doc(self):
self.assertEqual(CachedCostItem.cost.__doc__, "The cost of the item.")
+ def test_module(self):
+ self.assertEqual(CachedCostItem.cost.__module__, CachedCostItem.__module__)
+
def test_subclass_with___set__(self):
"""Caching still works for a subclass defining __set__."""
class readonly_cached_property(py_functools.cached_property):
--- /dev/null
+The ``__module__`` attribute on instances of :class:`functools.cached_property`
+is now set to the name of the module in which the cached_property is defined,
+rather than "functools". This means that doctests in ``cached_property``
+docstrings are now properly collected by the :mod:`doctest` module. Patch by
+Tyler Smart.