Skip to content

bpo-40838 document getdoc, getmodule, getsourcefile in inspect returns None #30575

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

Merged
merged 6 commits into from
May 18, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Doc/library/inspect.rst
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ Retrieving source code
If the documentation string for an object is not provided and the object is
a class, a method, a property or a descriptor, retrieve the documentation
string from the inheritance hierarchy.
Return ``None`` if the documentation string is invalid or missing.

.. versionchanged:: 3.5
Documentation strings are now inherited if not overridden.
Expand All @@ -535,12 +536,14 @@ Retrieving source code

.. function:: getmodule(object)

Try to guess which module an object was defined in.
Try to guess which module an object was defined in. Return ``None``
if the module cannot be determined.


.. function:: getsourcefile(object)

Return the name of the Python source file in which an object was defined. This
Return the name of the Python source file in which an object was defined
or ``None`` if no way can be identified to get the source. This
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
or ``None`` if no way can be identified to get the source. This
or ``None`` if it cannot be identified. This

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! But, I've copied this exact piece from inspect.py, I think it is better to keep it in sync (at least try to do that) 🙂

will fail with a :exc:`TypeError` if the object is a built-in module, class, or
function.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Document that :func:`inspect.getdoc`, :func:`inspect.getmodule`, and
:func:`inspect.getsourcefile` might return ``None``.