Skip to content

Commit 74329d9

Browse files
Fail better in ExceptionDocumenter.can_document_member (#11660)
Co-authored-by: Adam Turner <9087854+aa-turner@users.noreply.github.com>
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy