From 79fa283687c9b019b7d8e4c9f61f5815d0185b11 Mon Sep 17 00:00:00 2001 From: shimizukawa Date: Sat, 17 Dec 2016 23:18:30 +0900 Subject: [PATCH] Fix #3255: In Py3.4 environment, autodoc doesn't support documentation for attributes of Enum class correctly. --- CHANGES | 2 ++ sphinx/ext/autodoc.py | 11 ++++++++++- sphinx/util/inspect.py | 7 +++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 375701166..9040bc33d 100644 --- a/CHANGES +++ b/CHANGES @@ -14,6 +14,8 @@ Bugs fixed * #3253: In Py2 environment, building another locale with a non-captioned toctree produces ``None`` captions * #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) ===================================== diff --git a/sphinx/ext/autodoc.py b/sphinx/ext/autodoc.py index c3832bfda..efa642c8f 100644 --- a/sphinx/ext/autodoc.py +++ b/sphinx/ext/autodoc.py @@ -32,7 +32,8 @@ from sphinx.application import ExtensionError from sphinx.util.nodes import nested_parse_with_titles from sphinx.util.compat import Directive 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 try: @@ -774,6 +775,14 @@ class Documenter(object): else: members = [(mname, self.get_attr(self.object, mname, None)) 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) # add instance attributes from the analyzer for aname in analyzed_member_names: diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py index 147d43592..942a73654 100644 --- a/sphinx/util/inspect.py +++ b/sphinx/util/inspect.py @@ -100,6 +100,13 @@ except ImportError: 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): """Check if the object is attribute of enum.""" if enum is None: