summaryrefslogtreecommitdiff
path: root/doc/development/tutorials/examples/autodoc_intenum.py
diff options
context:
space:
mode:
authorJouke Witteveen <j.witteveen@gmail.com>2021-12-02 16:50:09 +0100
committerGitHub <noreply@github.com>2021-12-02 16:50:09 +0100
commitbc849e2170db3fa09dd498e4737a056c0fbfceaa (patch)
tree1b6c5e8ea734533e6a7dc6def42937fdf62b7adf /doc/development/tutorials/examples/autodoc_intenum.py
parent17dfa811078205bd415700361e97e945112b89eb (diff)
downloadsphinx-git-bc849e2170db3fa09dd498e4737a056c0fbfceaa.tar.gz
doc: Fix autodoc extension example
`directivetype` is set to mimic `ClassDocumenter`. Reflect that. `isinstance` would work on the enum members, but that is not what we want here. `issubclass` raises a TypeError when called on objects that are not classes.
Diffstat (limited to 'doc/development/tutorials/examples/autodoc_intenum.py')
-rw-r--r--doc/development/tutorials/examples/autodoc_intenum.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/doc/development/tutorials/examples/autodoc_intenum.py b/doc/development/tutorials/examples/autodoc_intenum.py
index 7fb85d066..574ac3621 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)