Skip to content

Commit 414739b

Browse files
Hywankernc
andauthored
REF: Don't warn on inaccessible source of builtins (#258)
* feat: Avoid trying to extract PEP-224 docstrings from builtins. If a module or a class is a builtins (e.g. from an extension), the `_pep224_docstrings` function will generate a lot of warnings. This patch skips the extraction of the PEP-224 docstrings for builtins modules or classes. * feat: Extract PEP-224 for builtins, but do not warn if none. * Fix 'builtins' determination logic `type(any_class) == type` and its `__module__` is always `'builtins'` Co-authored-by: Kernc <[email protected]>
1 parent d776cbd commit 414739b

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

pdoc/__init__.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,10 @@ def _pep224_docstrings(doc_obj: Union['Module', 'Class'], *,
258258
_ = inspect.findsource(doc_obj.obj)
259259
tree = ast.parse(doc_obj.source) # type: ignore
260260
except (OSError, TypeError, SyntaxError) as exc:
261-
warn("Couldn't read PEP-224 variable docstrings from {!r}: {}".format(doc_obj, exc))
261+
# Don't emit a warning for builtins that don't have source available
262+
is_builtin = getattr(doc_obj.obj, '__module__', None) == 'builtins'
263+
if not is_builtin:
264+
warn("Couldn't read PEP-224 variable docstrings from {!r}: {}".format(doc_obj, exc))
262265
return {}, {}
263266

264267
if isinstance(doc_obj, Class):

0 commit comments

Comments
 (0)