Skip to content

Commit da2616d

Browse files
committed
gh-107995: Fix doctest collection of functools.cached_property objects
1 parent a794ebe commit da2616d

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

Lib/functools.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,7 @@ def __init__(self, func):
984984
self.func = func
985985
self.attrname = None
986986
self.__doc__ = func.__doc__
987+
self.__module__ = func.__module__
987988

988989
def __set_name__(self, owner, name):
989990
if self.attrname is None:

Lib/test/test_doctest.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ def a_classmethod_property(cls):
111111
"""
112112
return cls.a_class_attribute
113113

114+
@functools.cached_property
115+
def a_cached_property(self):
116+
"""
117+
>>> print(SampleClass(29).get())
118+
29
119+
"""
120+
return "hello"
121+
114122
class NestedClass:
115123
"""
116124
>>> x = SampleClass.NestedClass(5)
@@ -515,6 +523,7 @@ def basics(): r"""
515523
3 SampleClass.NestedClass
516524
1 SampleClass.NestedClass.__init__
517525
1 SampleClass.__init__
526+
1 SampleClass.a_cached_property
518527
2 SampleClass.a_classmethod
519528
1 SampleClass.a_classmethod_property
520529
1 SampleClass.a_property
@@ -571,6 +580,7 @@ def basics(): r"""
571580
3 some_module.SampleClass.NestedClass
572581
1 some_module.SampleClass.NestedClass.__init__
573582
1 some_module.SampleClass.__init__
583+
1 some_module.SampleClass.a_cached_property
574584
2 some_module.SampleClass.a_classmethod
575585
1 some_module.SampleClass.a_classmethod_property
576586
1 some_module.SampleClass.a_property
@@ -613,6 +623,7 @@ def basics(): r"""
613623
3 SampleClass.NestedClass
614624
1 SampleClass.NestedClass.__init__
615625
1 SampleClass.__init__
626+
1 SampleClass.a_cached_property
616627
2 SampleClass.a_classmethod
617628
1 SampleClass.a_classmethod_property
618629
1 SampleClass.a_property
@@ -634,6 +645,7 @@ def basics(): r"""
634645
0 SampleClass.NestedClass.get
635646
0 SampleClass.NestedClass.square
636647
1 SampleClass.__init__
648+
1 SampleClass.a_cached_property
637649
2 SampleClass.a_classmethod
638650
1 SampleClass.a_classmethod_property
639651
1 SampleClass.a_property
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix :mod:`doctest` collection of :func:`functools.cached_property` objects.

0 commit comments

Comments
 (0)