From bc849e2170db3fa09dd498e4737a056c0fbfceaa Mon Sep 17 00:00:00 2001 From: Jouke Witteveen Date: Thu, 2 Dec 2021 16:50:09 +0100 Subject: [PATCH] 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. --- doc/development/tutorials/examples/autodoc_intenum.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/doc/development/tutorials/examples/autodoc_intenum.py b/doc/development/tutorials/examples/autodoc_intenum.py index 7fb85d0662e..574ac36213a 100644 --- a/doc/development/tutorials/examples/autodoc_intenum.py +++ b/doc/development/tutorials/examples/autodoc_intenum.py @@ -9,7 +9,7 @@ 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)