summaryrefslogtreecommitdiff
path: root/doc/development/tutorials/examples/autodoc_intenum.py
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2021-12-11 22:59:56 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2021-12-11 22:59:56 +0900
commit5563f672eccd3aa93c304ba6bac04ee2360b8c4e (patch)
tree48f26368337d0f2c3322aecd5a3e3db85c1b1682 /doc/development/tutorials/examples/autodoc_intenum.py
parent1227799abf0d0e3dafa0d61461cf613468e894df (diff)
parentc6fc5dff5334dc04c7858f2752a5e2c22f25eaeb (diff)
downloadsphinx-git-5563f672eccd3aa93c304ba6bac04ee2360b8c4e.tar.gz
Merge branch '4.x' into fix-footnote-in-info
Diffstat (limited to 'doc/development/tutorials/examples/autodoc_intenum.py')
-rw-r--r--doc/development/tutorials/examples/autodoc_intenum.py16
1 files changed, 9 insertions, 7 deletions
diff --git a/doc/development/tutorials/examples/autodoc_intenum.py b/doc/development/tutorials/examples/autodoc_intenum.py
index 7fb85d066..a23f9cebf 100644
--- a/doc/development/tutorials/examples/autodoc_intenum.py
+++ b/doc/development/tutorials/examples/autodoc_intenum.py
@@ -9,7 +9,7 @@ from sphinx.ext.autodoc import ClassDocumenter, bool_option
class IntEnumDocumenter(ClassDocumenter):
objtype = 'intenum'
- directivetype = 'class'
+ directivetype = ClassDocumenter.objtype
priority = 10 + ClassDocumenter.priority
option_spec = dict(ClassDocumenter.option_spec)
option_spec['hex'] = bool_option
@@ -18,7 +18,10 @@ class IntEnumDocumenter(ClassDocumenter):
def can_document_member(cls,
member: Any, membername: str,
isattr: bool, parent: Any) -> bool:
- return isinstance(member, IntEnum)
+ try:
+ return issubclass(member, IntEnum)
+ except TypeError:
+ return False
def add_directive_header(self, sig: str) -> None:
super().add_directive_header(sig)
@@ -36,14 +39,13 @@ class IntEnumDocumenter(ClassDocumenter):
use_hex = self.options.hex
self.add_line('', source_name)
- for enum_value in enum_object:
- the_value_name = enum_value.name
- the_value_value = enum_value.value
+ for the_member_name, enum_member in enum_object.__members__.items():
+ the_member_value = enum_member.value
if use_hex:
- the_value_value = hex(the_value_value)
+ the_member_value = hex(the_member_value)
self.add_line(
- f"**{the_value_name}**: {the_value_value}", source_name)
+ f"**{the_member_name}**: {the_member_value}", source_name)
self.add_line('', source_name)