summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2020-04-30 22:54:49 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2020-04-30 22:54:49 +0900
commitd612ef8f0ba9d608a2aace13b96f3d6d4054c4fc (patch)
treea97df493bf28c80eca73946babb3660f1d2e755b
parent5460ad6925199b57b27b7d059825d3560872edbb (diff)
downloadsphinx-git-d612ef8f0ba9d608a2aace13b96f3d6d4054c4fc.tar.gz
Fix #6857: autodoc: failed to detect a classmethod on Enum class
-rw-r--r--CHANGES1
-rw-r--r--sphinx/ext/autodoc/importer.py3
-rw-r--r--tests/roots/test-ext-autodoc/target/enum.py5
-rw-r--r--tests/test_autodoc.py15
4 files changed, 16 insertions, 8 deletions
diff --git a/CHANGES b/CHANGES
index 44be3fbf9..7e1ac3aac 100644
--- a/CHANGES
+++ b/CHANGES
@@ -74,6 +74,7 @@ Bugs fixed
* #6588: autodoc: Decorated inherited method has no documentation
* #7469: autodoc: The change of autodoc-process-docstring for variables is
cached unexpectedly
+* #6857: autodoc: failed to detect a classmethod on Enum class
* #7535: sphinx-autogen: crashes when custom template uses inheritance
* #7536: sphinx-autogen: crashes when template uses i18n feature
* #2785: html: Bad alignment of equation links
diff --git a/sphinx/ext/autodoc/importer.py b/sphinx/ext/autodoc/importer.py
index e98b97915..432aa0c85 100644
--- a/sphinx/ext/autodoc/importer.py
+++ b/sphinx/ext/autodoc/importer.py
@@ -142,8 +142,9 @@ def get_object_members(subject: Any, objpath: List[str], attrgetter: Callable,
members[name] = Attribute(name, True, value)
superclass = subject.__mro__[1]
- for name, value in obj_dict.items():
+ for name in obj_dict:
if name not in superclass.__dict__:
+ value = safe_getattr(subject, name)
members[name] = Attribute(name, True, value)
# members in __slots__
diff --git a/tests/roots/test-ext-autodoc/target/enum.py b/tests/roots/test-ext-autodoc/target/enum.py
index d0a59c71c..c69455fb7 100644
--- a/tests/roots/test-ext-autodoc/target/enum.py
+++ b/tests/roots/test-ext-autodoc/target/enum.py
@@ -16,3 +16,8 @@ class EnumCls(enum.Enum):
def say_hello(self):
"""a method says hello to you."""
pass
+
+ @classmethod
+ def say_goodbye(cls):
+ """a classmethod says good-bye to you."""
+ pass
diff --git a/tests/test_autodoc.py b/tests/test_autodoc.py
index cbbdbb787..aedaa75cf 100644
--- a/tests/test_autodoc.py
+++ b/tests/test_autodoc.py
@@ -1112,8 +1112,7 @@ def test_slots(app):
@pytest.mark.sphinx('html', testroot='ext-autodoc')
def test_enum_class(app):
- options = {"members": None,
- "undoc-members": True}
+ options = {"members": None}
actual = do_autodoc(app, 'class', 'target.enum.EnumCls', options)
assert list(actual) == [
'',
@@ -1123,6 +1122,13 @@ def test_enum_class(app):
' this is enum class',
'',
'',
+ ' .. py:method:: EnumCls.say_goodbye()',
+ ' :module: target.enum',
+ ' :classmethod:',
+ '',
+ ' a classmethod says good-bye to you.',
+ '',
+ '',
' .. py:method:: EnumCls.say_hello()',
' :module: target.enum',
'',
@@ -1149,11 +1155,6 @@ def test_enum_class(app):
'',
' doc for val3',
'',
- '',
- ' .. py:attribute:: EnumCls.val4',
- ' :module: target.enum',
- ' :value: 34',
- ''
]
# checks for an attribute of EnumClass