bpo-17972: Document findsource in inspect.rst by Carreau · Pull Request #6992 · python/cpython (original) (raw)

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 andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation6 Commits1 Checks0 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

Carreau

@Carreau

From the discussion in bpo-1792, it seem that findsource is mostly low level, while getsource is higher level.

This does not completely fix bpo-17972 as many methonds need to be marked either private, or documented

JulienPalard

Choose a reason for hiding this comment

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

LGTM with nits.

You could maybe also state that findsource does not unwraps?

@@ -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`

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:

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.

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 ...
Return the entire source file and starting line number for an object.
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

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.

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
in the file and the line number indexes a line in that list. An OSError

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):

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`

@bedevere-bot

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.