Skip to content

Commit

Permalink
Fail better in ExceptionDocumenter.can_document_member (#11660)
Browse files Browse the repository at this point in the history
Co-authored-by: Adam Turner <9087854+aa-turner@users.noreply.github.com>
  • Loading branch information
jamesbraza and AA-Turner authored Aug 30, 2023
1 parent 7d046a8 commit 74329d9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------
Expand Down
12 changes: 11 additions & 1 deletion sphinx/ext/autodoc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 74329d9

Please sign in to comment.