-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
bpo-16355: fix a lack in inspect.getcomments() doc #428
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 and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@marco-buttu, thanks for your PR! By analyzing the history of the files in this pull request, we identified @birkenfeld, @1st1, @asvetlov, @ncoghlan and @voidspace to be potential reviewers. |
Note: Commit message should include "Initial patch by Vajrasky Kok.". |
Lib/test/test_inspect.py
Outdated
from test.support import run_unittest, TESTFN, DirsOnSysPath, cpython_only | ||
from test.support import MISSING_C_DOCSTRINGS, cpython_only | ||
from test.support import (run_unittest, TESTFN, DirsOnSysPath, cpython_only, | ||
MISSING_C_DOCSTRINGS) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look like a relevant change to bpo-16355. Please send a separate PR for this.
Anyway, I prefer hanging indentation style:
from test.support import (
MISSING_C_DOCSTRINGS, TESTFN, DirsOnSysPath, cpython_only, run_unittest,
)
Lib/test/test_inspect.py
Outdated
@@ -384,6 +384,12 @@ def test_cleandoc(self): | |||
def test_getcomments(self): | |||
self.assertEqual(inspect.getcomments(mod), '# line 1\n') | |||
self.assertEqual(inspect.getcomments(mod.StupidGit), '# line 20\n') | |||
# If the object source file is not available, return None | |||
fn = "_non_existing_filename_used_for_sourcefile_test.py" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_non_existing_filename.py
is both short and descriptive. Also, this way you can avoid using a fn
variable.
Lib/test/test_inspect.py
Outdated
@@ -384,6 +384,12 @@ def test_cleandoc(self): | |||
def test_getcomments(self): | |||
self.assertEqual(inspect.getcomments(mod), '# line 1\n') | |||
self.assertEqual(inspect.getcomments(mod.StupidGit), '# line 20\n') | |||
# If the object source file is not available, return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finish sentences with full stops.
Thanks @berkerpeksag, fixed |
Lib/test/test_inspect.py
Outdated
@@ -384,6 +384,11 @@ def test_cleandoc(self): | |||
def test_getcomments(self): | |||
self.assertEqual(inspect.getcomments(mod), '# line 1\n') | |||
self.assertEqual(inspect.getcomments(mod.StupidGit), '# line 20\n') | |||
# If the object source file is not available, return None. | |||
co = compile("x=1", '_non_existing_filename.py', "exec") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use single quotes like the rest of the test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @berkerpeksag, done.
Why don't we raise an error if we can't find the source? Why returning |
@1st1, in bpo-16355 @ezio-melotti and @bitdancer discussed about raising an error or not, and eventually they agreed to return |
I see. The idea is to preserve the backwards compatibility. Then LGTM. |
Doc/library/inspect.rst
Outdated
Python source file (if the object is a module). | ||
Python source file (if the object is a module). If the object's source code | ||
is unavailable, return ``None``. This could happen if the object has been | ||
defined in C or interactive shell. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or the interactive shell
Thanks! |
Initial patch by Vajrasky Kok. (cherry picked from commit 3f2155f)
Initial patch by Vajrasky Kok. (cherry picked from commit 3f2155f)
Fix bpo-16355.