Skip to content

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

Merged
merged 5 commits into from
Mar 17, 2017
Merged

bpo-16355: fix a lack in inspect.getcomments() doc #428

merged 5 commits into from
Mar 17, 2017

Conversation

marco-buttu
Copy link
Contributor

Fix bpo-16355.

@mention-bot
Copy link

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

@marco-buttu marco-buttu changed the title bpo-16355: fix a lack in inspect.getcomments() bpo-16355: fix a lack in inspect.getcomments() doc Mar 3, 2017
@berkerpeksag
Copy link
Member

Note: Commit message should include "Initial patch by Vajrasky Kok.".

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)
Copy link
Member

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

@@ -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"
Copy link
Member

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.

@@ -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
Copy link
Member

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.

@marco-buttu
Copy link
Contributor Author

Thanks @berkerpeksag, fixed

@@ -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")
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @berkerpeksag, done.

@1st1
Copy link
Member

1st1 commented Mar 16, 2017

Why don't we raise an error if we can't find the source? Why returning None?

@marco-buttu
Copy link
Contributor Author

@1st1, in bpo-16355 @ezio-melotti and @bitdancer discussed about raising an error or not, and eventually they agreed to return None.

@1st1
Copy link
Member

1st1 commented Mar 16, 2017

I see. The idea is to preserve the backwards compatibility. Then LGTM.

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.
Copy link
Member

Choose a reason for hiding this comment

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

or the interactive shell

@berkerpeksag berkerpeksag merged commit 3f2155f into python:master Mar 17, 2017
@berkerpeksag
Copy link
Member

Thanks!

berkerpeksag pushed a commit to berkerpeksag/cpython that referenced this pull request Mar 17, 2017
Initial patch by Vajrasky Kok.

(cherry picked from commit 3f2155f)
berkerpeksag pushed a commit to berkerpeksag/cpython that referenced this pull request Mar 17, 2017
Initial patch by Vajrasky Kok.

(cherry picked from commit 3f2155f)
berkerpeksag added a commit that referenced this pull request Mar 17, 2017
Initial patch by Vajrasky Kok.

(cherry picked from commit 3f2155f)
berkerpeksag added a commit that referenced this pull request Mar 17, 2017
Initial patch by Vajrasky Kok.

(cherry picked from commit 3f2155f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants