From 5de83cac388b0a797a048ef1148975dceba529f2 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Thu, 13 Jan 2022 16:05:06 +0300 Subject: [PATCH 1/5] bpo-40838 document `getdoc`, `getmodule`, `getsourcefile` in `inspect` returns `None` --- Doc/library/inspect.rst | 7 +++++-- .../Documentation/2022-01-13-16-03-15.bpo-40838.k3NVCf.rst | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Documentation/2022-01-13-16-03-15.bpo-40838.k3NVCf.rst diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst index 711f510d7dcb03..31e23ac11820da 100644 --- a/Doc/library/inspect.rst +++ b/Doc/library/inspect.rst @@ -503,6 +503,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. + Might return ``None`` for invalid docstrings. .. versionchanged:: 3.5 Documentation strings are now inherited if not overridden. @@ -526,12 +527,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. Might return ``None`` + in case of an error. .. 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 00000000000000..0f071ab64dbecc --- /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``. From c15b947d247df850d4a48172bd85d1ee3ea2206e Mon Sep 17 00:00:00 2001 From: sobolevn Date: Thu, 13 Jan 2022 16:29:58 +0300 Subject: [PATCH 2/5] Improve `getdoc` --- Doc/library/inspect.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst index 31e23ac11820da..66eb5206e6d1c1 100644 --- a/Doc/library/inspect.rst +++ b/Doc/library/inspect.rst @@ -503,7 +503,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. - Might return ``None`` for invalid docstrings. + Might return ``None`` for missing or invalid docstrings. .. versionchanged:: 3.5 Documentation strings are now inherited if not overridden. From da08f67f5233c7f6e1e89ef84466080b090a2eb0 Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Fri, 14 Jan 2022 12:05:52 +0300 Subject: [PATCH 3/5] Update Doc/library/inspect.rst Co-authored-by: Alex Waygood --- Doc/library/inspect.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst index 66eb5206e6d1c1..f5043bbf8f315c 100644 --- a/Doc/library/inspect.rst +++ b/Doc/library/inspect.rst @@ -503,7 +503,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. - Might return ``None`` for missing or invalid docstrings. + Return ``None`` if the documentation string is invalid or missing. .. versionchanged:: 3.5 Documentation strings are now inherited if not overridden. From eaa4292622fa140a5a62cc4f5c3650d9a95fdcec Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Fri, 14 Jan 2022 12:05:58 +0300 Subject: [PATCH 4/5] Update Doc/library/inspect.rst Co-authored-by: Alex Waygood --- Doc/library/inspect.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst index f5043bbf8f315c..a9455d3e04399d 100644 --- a/Doc/library/inspect.rst +++ b/Doc/library/inspect.rst @@ -527,7 +527,7 @@ Retrieving source code .. function:: getmodule(object) - Try to guess which module an object was defined in. Might return ``None`` + Try to guess which module an object was defined in. Return ``None`` in case of an error. From 913f07ae02ab2c9665ecd6456e4694c2dab59847 Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Fri, 21 Jan 2022 10:15:27 +0300 Subject: [PATCH 5/5] Update Doc/library/inspect.rst Co-authored-by: Jelle Zijlstra --- Doc/library/inspect.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst index a9455d3e04399d..c3aa202bfcd821 100644 --- a/Doc/library/inspect.rst +++ b/Doc/library/inspect.rst @@ -528,7 +528,7 @@ Retrieving source code .. function:: getmodule(object) Try to guess which module an object was defined in. Return ``None`` - in case of an error. + if the module cannot be determined. .. function:: getsourcefile(object)