bpo-16355: fix a lack in inspect.getcomments() doc#428
bpo-16355: fix a lack in inspect.getcomments() doc#428berkerpeksag merged 5 commits intopython:masterfrom marco-buttu:fix-issue-16355
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.
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
| 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.
_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
| 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.
Finish sentences with full stops.
|
Thanks @berkerpeksag, fixed |
Lib/test/test_inspect.py
Outdated
| 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.
Please use single quotes like the rest of the test.
|
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. |
|
Thanks! |
Initial patch by Vajrasky Kok. (cherry picked from commit 3f2155f)
Initial patch by Vajrasky Kok. (cherry picked from commit 3f2155f)
Fix bpo-16355.