summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_doctest.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-10-28 08:09:41 (GMT)
committerGitHub <noreply@github.com>2021-10-28 08:09:41 (GMT)
commit1f45cc0dfa9a8febfc256411c803b4536719db97 (patch)
tree2049fe508942ef5439b1d5f0afd4e4f05c63c0be /Lib/test/test_doctest.py
parentce7a6afb797d2ffde45e9e902516b8437c8f9e31 (diff)
downloadcpython-1f45cc0dfa9a8febfc256411c803b4536719db97.zip
cpython-1f45cc0dfa9a8febfc256411c803b4536719db97.tar.gz
cpython-1f45cc0dfa9a8febfc256411c803b4536719db97.tar.bz2
bpo-44904: Fix classmethod property bug in doctest module (GH-28838)
The doctest module raised an error if a docstring contained an example that attempted to access a classmethod property. (Stacking '@classmethod' on top of `@property` has been supported since Python 3.9; see https://docs.python.org/3/howto/descriptor.htmlGH-class-methods.) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> (cherry picked from commit b1302abcc8a4be5f39b4d60a1ce28032b77655b3) Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Diffstat (limited to 'Lib/test/test_doctest.py')
-rw-r--r--Lib/test/test_doctest.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_doctest.py b/Lib/test/test_doctest.py
index 7f8ccd3..9703f87 100644
--- a/Lib/test/test_doctest.py
+++ b/Lib/test/test_doctest.py
@@ -96,6 +96,17 @@ class SampleClass:
22
""")
+ a_class_attribute = 42
+
+ @classmethod
+ @property
+ def a_classmethod_property(cls):
+ """
+ >>> print(SampleClass.a_classmethod_property)
+ 42
+ """
+ return cls.a_class_attribute
+
class NestedClass:
"""
>>> x = SampleClass.NestedClass(5)
@@ -501,6 +512,7 @@ methods, classmethods, staticmethods, properties, and nested classes.
1 SampleClass.NestedClass.__init__
1 SampleClass.__init__
2 SampleClass.a_classmethod
+ 1 SampleClass.a_classmethod_property
1 SampleClass.a_property
1 SampleClass.a_staticmethod
1 SampleClass.double
@@ -556,6 +568,7 @@ functions, classes, and the `__test__` dictionary, if it exists:
1 some_module.SampleClass.NestedClass.__init__
1 some_module.SampleClass.__init__
2 some_module.SampleClass.a_classmethod
+ 1 some_module.SampleClass.a_classmethod_property
1 some_module.SampleClass.a_property
1 some_module.SampleClass.a_staticmethod
1 some_module.SampleClass.double
@@ -597,6 +610,7 @@ By default, an object with no doctests doesn't create any tests:
1 SampleClass.NestedClass.__init__
1 SampleClass.__init__
2 SampleClass.a_classmethod
+ 1 SampleClass.a_classmethod_property
1 SampleClass.a_property
1 SampleClass.a_staticmethod
1 SampleClass.double
@@ -617,6 +631,7 @@ displays.
0 SampleClass.NestedClass.square
1 SampleClass.__init__
2 SampleClass.a_classmethod
+ 1 SampleClass.a_classmethod_property
1 SampleClass.a_property
1 SampleClass.a_staticmethod
1 SampleClass.double