Skip to content
Closed
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
15 changes: 15 additions & 0 deletions Doc/library/inspect.rst
Original file line number Diff line number Diff line change
Expand Up @@ -511,10 +511,25 @@ Retrieving source code
returned as a single string. An :exc:`OSError` is raised if the source code
cannot be retrieved.

If *object* is a wrapper function (that is to say has a :attr:`__wrapped__`
field, :func:`getsource` will follows the chain of :attr:`__wrapped__`
attributes returning the last object in the chain using :func:`unwrap`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Missing a dot at end of sentence:

Suggested change
attributes returning the last object in the chain using :func:`unwrap`
attributes returning the last object in the chain using :func:`unwrap`.


.. versionchanged:: 3.3
:exc:`OSError` is raised instead of :exc:`IOError`, now an alias of the
former.

.. function:: findsource(object)

Return the entire source file and starting line number for an object.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd be explicit that the function is returning a tuple, maybe by starting like this and describing both elements:

Return a tuple ``(lines, lnum)`` where *lines* is ...


The argument may be a module, class, method, function, traceback, frame,
or code object. The source code is returned as a list of all the lines
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The sentence starting here may be redundent if you fix the previous comment.

in the file and the line number indexes a line in that list. An OSError
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please link to the actual exception, at least as a visual hint while reading (this make it rendered differently in HTML):

Suggested change
in the file and the line number indexes a line in that list. An OSError
in the file and the line number indexes a line in that list. An :exc:`OSError`

is raised if the source code cannot be retrieved.

Prefer the use of :func:`getsource` if possible.


.. function:: cleandoc(doc)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Document :func:`inspect.findsource`