Kaydet (Commit) 948171bf authored tarafından Berker Peksag's avatar Berker Peksag Kaydeden (comit) GitHub

bpo-16355: Clarify when inspect.getcomments() returns None (#428) (#690)

Initial patch by Vajrasky Kok.

(cherry picked from commit 3f2155ff)
üst 7c208112
...@@ -442,7 +442,9 @@ Retrieving source code ...@@ -442,7 +442,9 @@ Retrieving source code
Return in a single string any lines of comments immediately preceding the Return in a single string any lines of comments immediately preceding the
object's source code (for a class, function, or method), or at the top of the object's source code (for a class, function, or method), or at the top of the
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 the interactive shell.
.. function:: getfile(object) .. function:: getfile(object)
......
...@@ -387,6 +387,11 @@ class TestRetrievingSourceCode(GetSourceBase): ...@@ -387,6 +387,11 @@ class TestRetrievingSourceCode(GetSourceBase):
def test_getcomments(self): def test_getcomments(self):
self.assertEqual(inspect.getcomments(mod), '# line 1\n') self.assertEqual(inspect.getcomments(mod), '# line 1\n')
self.assertEqual(inspect.getcomments(mod.StupidGit), '# line 20\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')
self.assertIsNone(inspect.getcomments(co))
# If the object has been defined in C, return None.
self.assertIsNone(inspect.getcomments(list))
def test_getmodule(self): def test_getmodule(self):
# Check actual module # Check actual module
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment