Fail better in `ExceptionDocumenter.can_document_member` (#11660)

Co-authored-by: Adam Turner <9087854+aa-turner@users.noreply.github.com>
This commit is contained in:
James Braza 2023-08-30 11:49:27 -07:00 committed by GitHub
parent 7d046a862f
commit 74329d9c51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -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 an object claims to be an instance of ``type``,
but is not a class.
Patch by James Braza.
Testing
-------

View File

@ -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: