Fix #3255: In Py3.4 environment, autodoc doesn't support documentation for attributes of Enum class correctly.

This commit is contained in:
shimizukawa 2016-12-17 23:18:30 +09:00
parent 3b9aee43a2
commit 79fa283687
3 changed files with 19 additions and 1 deletions

View File

@ -14,6 +14,8 @@ Bugs fixed
* #3253: In Py2 environment, building another locale with a non-captioned * #3253: In Py2 environment, building another locale with a non-captioned
toctree produces ``None`` captions toctree produces ``None`` captions
* #185: References to section title including raw node has broken * #185: References to section title including raw node has broken
* #3255: In Py3.4 environment, autodoc doesn't support documentation for
attributes of Enum class correctly.
Release 1.5.1 (released Dec 13, 2016) Release 1.5.1 (released Dec 13, 2016)
===================================== =====================================

View File

@ -32,7 +32,8 @@ from sphinx.application import ExtensionError
from sphinx.util.nodes import nested_parse_with_titles from sphinx.util.nodes import nested_parse_with_titles
from sphinx.util.compat import Directive from sphinx.util.compat import Directive
from sphinx.util.inspect import getargspec, isdescriptor, safe_getmembers, \ from sphinx.util.inspect import getargspec, isdescriptor, safe_getmembers, \
safe_getattr, object_description, is_builtin_class_method, isenumattribute safe_getattr, object_description, is_builtin_class_method, \
isenumclass, isenumattribute
from sphinx.util.docstrings import prepare_docstring from sphinx.util.docstrings import prepare_docstring
try: try:
@ -774,6 +775,14 @@ class Documenter(object):
else: else:
members = [(mname, self.get_attr(self.object, mname, None)) members = [(mname, self.get_attr(self.object, mname, None))
for mname in list(iterkeys(obj_dict))] for mname in list(iterkeys(obj_dict))]
# Py34 doesn't have enum members in __dict__.
if isenumclass(self.object):
members.extend(
item for item in self.object.__members__.items()
if item not in members
)
membernames = set(m[0] for m in members) membernames = set(m[0] for m in members)
# add instance attributes from the analyzer # add instance attributes from the analyzer
for aname in analyzed_member_names: for aname in analyzed_member_names:

View File

@ -100,6 +100,13 @@ except ImportError:
enum = None enum = None
def isenumclass(x):
"""Check if the object is subclass of enum."""
if enum is None:
return False
return issubclass(x, enum.Enum)
def isenumattribute(x): def isenumattribute(x):
"""Check if the object is attribute of enum.""" """Check if the object is attribute of enum."""
if enum is None: if enum is None: