Skip to content

Commit 74329d9

Browse files
Fail better in ExceptionDocumenter.can_document_member (#11660)
Co-authored-by: Adam Turner <[email protected]>
1 parent 7d046a8 commit 74329d9

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

CHANGES

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ Bugs fixed
2424
for sibling files in a subdirectory.
2525
Patch by Albert Shih.
2626
* #11659: Allow ``?config=...`` in :confval:`mathjax_path`.
27+
* #11654: autodoc: Fail with a more descriptive error message
28+
when an object claims to be an instance of ``type``,
29+
but is not a class.
30+
Patch by James Braza.
2731

2832
Testing
2933
-------

sphinx/ext/autodoc/__init__.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1913,7 +1913,17 @@ class ExceptionDocumenter(ClassDocumenter):
19131913
@classmethod
19141914
def can_document_member(cls, member: Any, membername: str, isattr: bool, parent: Any,
19151915
) -> bool:
1916-
return isinstance(member, type) and issubclass(member, BaseException)
1916+
try:
1917+
return isinstance(member, type) and issubclass(member, BaseException)
1918+
except TypeError as exc:
1919+
# It's possible for a member to be considered a type, but fail
1920+
# issubclass checks due to not being a class. For example:
1921+
# https://github.com/sphinx-doc/sphinx/issues/11654#issuecomment-1696790436
1922+
msg = (
1923+
f'{cls.__name__} failed to discern if member {member} with'
1924+
f' membername {membername} is a BaseException subclass.'
1925+
)
1926+
raise ValueError(msg) from exc
19171927

19181928

19191929
class DataDocumenterMixinBase:

0 commit comments

Comments
 (0)