From ccd3a7d62aa1f974174aeaa7d1b857b5a9087a63 Mon Sep 17 00:00:00 2001 From: James Braza Date: Tue, 29 Aug 2023 22:57:14 -0700 Subject: [PATCH 1/4] Nice-ified TypeError coming out of ExceptionDocumenter.can_document_member --- sphinx/ext/autodoc/__init__.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py index ac1b5cec6f6..8d68f72bcbd 100644 --- a/sphinx/ext/autodoc/__init__.py +++ b/sphinx/ext/autodoc/__init__.py @@ -1913,7 +1913,17 @@ class ExceptionDocumenter(ClassDocumenter): @classmethod def can_document_member(cls, member: Any, membername: str, isattr: bool, parent: Any, ) -> bool: - return isinstance(member, type) and issubclass(member, BaseException) + try: + return isinstance(member, type) and issubclass(member, BaseException) + except TypeError as exc: + # It's possible for a member to be considered a type, but fail + # issubclass checks due to not being a class. For example: + # https://github.com/sphinx-doc/sphinx/issues/11654#issuecomment-1696790436 + msg = ( + f'{cls.__name__} failed to discern if member {member} with' + f' membername {membername} is a BaseException subclass.' + ) + raise ValueError(msg) from exc class DataDocumenterMixinBase: From fcfbc3e66b1f10de872eafe66c995d762dfa0b8a Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Wed, 30 Aug 2023 19:40:55 +0100 Subject: [PATCH 2/4] CHANGES --- CHANGES | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES b/CHANGES index 64aa161dfe2..dc421f14775 100644 --- a/CHANGES +++ b/CHANGES @@ -24,6 +24,10 @@ Bugs fixed for sibling files in a subdirectory. Patch by Albert Shih. * #11659: Allow ``?config=...`` in :confval:`mathjax_path`. +* #11654: autodoc: Fail with a more descriptive error message + when a class member claims to be an instance of ``type``, + but is not a class. + Patch by James Braza. Testing ------- From 46945ba2663ac5edcb46bdd81bb2c14fbf9526e6 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Wed, 30 Aug 2023 19:42:39 +0100 Subject: [PATCH 3/4] CHANGES --- CHANGES | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index dc421f14775..b5b45702220 100644 --- a/CHANGES +++ b/CHANGES @@ -25,7 +25,7 @@ Bugs fixed Patch by Albert Shih. * #11659: Allow ``?config=...`` in :confval:`mathjax_path`. * #11654: autodoc: Fail with a more descriptive error message - when a class member claims to be an instance of ``type``, + when an exception claims to be an instance of ``type``, but is not a class. Patch by James Braza. From 913083c07c71cbada42443c84ce60f4a2e05984c Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Wed, 30 Aug 2023 19:43:41 +0100 Subject: [PATCH 4/4] CHANGES --- CHANGES | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index b5b45702220..7d155ba8158 100644 --- a/CHANGES +++ b/CHANGES @@ -25,7 +25,7 @@ Bugs fixed Patch by Albert Shih. * #11659: Allow ``?config=...`` in :confval:`mathjax_path`. * #11654: autodoc: Fail with a more descriptive error message - when an exception claims to be an instance of ``type``, + when an object claims to be an instance of ``type``, but is not a class. Patch by James Braza.