Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExceptionDocumenter.can_document_member nicer TypeError #11660

Merged
merged 5 commits into from Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES
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
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