Skip to content

Commit

Permalink
Fix #6857: autodoc: failed to detect a classmethod on Enum class
Browse files Browse the repository at this point in the history
  • Loading branch information
tk0miya committed Apr 30, 2020
1 parent 5460ad6 commit d612ef8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion sphinx/ext/autodoc/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down
5 changes: 5 additions & 0 deletions tests/roots/test-ext-autodoc/target/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 8 additions & 7 deletions tests/test_autodoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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) == [
'',
Expand All @@ -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',
'',
Expand All @@ -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
Expand Down

0 comments on commit d612ef8

Please sign in to comment.