[Python-checkins] bpo-40838: document `getdoc`, `getmodule`, `getsourcefile` in `inspect` returns `None` (GH-30575)
miss-islington
webhook-mailer at python.org
Wed May 18 08:49:49 EDT 2022
https://github.com/python/cpython/commit/ed75d2183f9084583e2ebe9229c52711d4a62f1e
commit: ed75d2183f9084583e2ebe9229c52711d4a62f1e
branch: 3.10
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2022-05-18T05:49:15-07:00
summary:
bpo-40838: document `getdoc`, `getmodule`, `getsourcefile` in `inspect` returns `None` (GH-30575)
Co-authored-by: Alex Waygood <Alex.Waygood at Gmail.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra at gmail.com>
(cherry picked from commit b86d783a4eff96306f315acf9a6f1aca85d47fc3)
Co-authored-by: Nikita Sobolev <mail at sobolevn.me>
files:
A Misc/NEWS.d/next/Documentation/2022-01-13-16-03-15.bpo-40838.k3NVCf.rst
M Doc/library/inspect.rst
diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst
index d7ef2adf7281b..44553afc33b75 100644
--- a/Doc/library/inspect.rst
+++ b/Doc/library/inspect.rst
@@ -482,6 +482,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.
@@ -505,12 +506,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
will fail with a :exc:`TypeError` if the object is a built-in module, class, or
function.
diff --git a/Misc/NEWS.d/next/Documentation/2022-01-13-16-03-15.bpo-40838.k3NVCf.rst b/Misc/NEWS.d/next/Documentation/2022-01-13-16-03-15.bpo-40838.k3NVCf.rst
new file mode 100644
index 0000000000000..0f071ab64dbec
--- /dev/null
+++ b/Misc/NEWS.d/next/Documentation/2022-01-13-16-03-15.bpo-40838.k3NVCf.rst
@@ -0,0 +1,2 @@
+Document that :func:`inspect.getdoc`, :func:`inspect.getmodule`, and
+:func:`inspect.getsourcefile` might return ``None``.
More information about the Python-checkins
mailing list