From 52b3481289760a0b92da4ec1ab87ff3d4f153be1 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Wed, 8 Feb 2023 14:58:15 +0300 Subject: [PATCH 1/2] gh-98239: Document that `inspect.getsource()` can raise `TypeError` --- Doc/library/inspect.rst | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst index 58b84a35a890e3..720f4727b426c3 100644 --- a/Doc/library/inspect.rst +++ b/Doc/library/inspect.rst @@ -573,7 +573,9 @@ Retrieving source code object. The source code is returned as a list of the lines corresponding to the object and the line number indicates where in the original source file the first line of code was found. An :exc:`OSError` is raised if the source code cannot - be retrieved. + be retrieved. This + will fail with a :exc:`TypeError` if the object is a built-in module, class, or + function. .. versionchanged:: 3.3 :exc:`OSError` is raised instead of :exc:`IOError`, now an alias of the @@ -585,7 +587,9 @@ Retrieving source code Return the text of the source code for an object. The argument may be a module, class, method, function, traceback, frame, or code object. The source code is returned as a single string. An :exc:`OSError` is raised if the source code - cannot be retrieved. + cannot be retrieved. This + will fail with a :exc:`TypeError` if the object is a built-in module, class, or + function. .. versionchanged:: 3.3 :exc:`OSError` is raised instead of :exc:`IOError`, now an alias of the From d08f2d8601fe287de42ae2b30fdfe24b1a2e6e74 Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Thu, 23 Mar 2023 22:25:11 +0300 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Alex Waygood --- Doc/library/inspect.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst index 720f4727b426c3..0e493a1806cae6 100644 --- a/Doc/library/inspect.rst +++ b/Doc/library/inspect.rst @@ -573,8 +573,8 @@ Retrieving source code object. The source code is returned as a list of the lines corresponding to the object and the line number indicates where in the original source file the first line of code was found. An :exc:`OSError` is raised if the source code cannot - be retrieved. This - will fail with a :exc:`TypeError` if the object is a built-in module, class, or + be retrieved. + A :exc:`TypeError` is raised if the object is a built-in module, class, or function. .. versionchanged:: 3.3 @@ -587,8 +587,8 @@ Retrieving source code Return the text of the source code for an object. The argument may be a module, class, method, function, traceback, frame, or code object. The source code is returned as a single string. An :exc:`OSError` is raised if the source code - cannot be retrieved. This - will fail with a :exc:`TypeError` if the object is a built-in module, class, or + cannot be retrieved. + A :exc:`TypeError` is raised if the object is a built-in module, class, or function. .. versionchanged:: 3.3