Skip to content

Commit

Permalink
pythongh-107995: Fix doctest collection of functools.cached_property …
Browse files Browse the repository at this point in the history
…objects
  • Loading branch information
tjsmart committed Aug 18, 2023
1 parent a794ebe commit da2616d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions Lib/functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,7 @@ def __init__(self, func):
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:
Expand Down
12 changes: 12 additions & 0 deletions Lib/test/test_doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ def a_classmethod_property(cls):
"""
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)
Expand Down Expand Up @@ -515,6 +523,7 @@ def basics(): r"""
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
Expand Down Expand Up @@ -571,6 +580,7 @@ def basics(): r"""
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
Expand Down Expand Up @@ -613,6 +623,7 @@ def basics(): r"""
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
Expand All @@ -634,6 +645,7 @@ def basics(): r"""
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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix :mod:`doctest` collection of :func:`functools.cached_property` objects.

0 comments on commit da2616d

Please sign in to comment.