]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #24669: Fix inspect.getsource() for 'async def' functions.
authorYury Selivanov <yselivanov@sprymix.com>
Tue, 21 Jul 2015 16:01:52 +0000 (19:01 +0300)
committerYury Selivanov <yselivanov@sprymix.com>
Tue, 21 Jul 2015 16:01:52 +0000 (19:01 +0300)
Patch by Kai Groner.

Lib/inspect.py
Lib/test/inspect_fodder.py
Lib/test/test_inspect.py
Misc/NEWS

index 42f24cddba8745f09245d4331f1328140a62562d..4c1ac1f283d006e6cad60cd4e7a56f0c46f5f227 100644 (file)
@@ -798,7 +798,7 @@ def findsource(object):
         if not hasattr(object, 'co_firstlineno'):
             raise OSError('could not find function definition')
         lnum = object.co_firstlineno - 1
-        pat = re.compile(r'^(\s*def\s)|(.*(?<!\w)lambda(:|\s))|^(\s*@)')
+        pat = re.compile(r'^(\s*def\s)|(\s*async\s+def\s)|(.*(?<!\w)lambda(:|\s))|^(\s*@)')
         while lnum > 0:
             if pat.match(lines[lnum]): break
             lnum = lnum - 1
index 6f0cad942d35858f628191a7e8ef3945b06c6e3a..068d8258b925d2c3b750d6e1e6971afd4c0f12cf 100644 (file)
@@ -66,3 +66,6 @@ class FesteringGob(MalodorousPervert, ParrotDroppings):
         pass
     def contradiction(self):
         pass
+
+async def lobbest(grenade):
+    pass
index 8e0e73cf007d5371b5c837a214d10b95b83feed2..e6208935a7d382b1a2b195575e9f3d47ec88b69e 100644 (file)
@@ -336,6 +336,7 @@ class TestRetrievingSourceCode(GetSourceBase):
     def test_getfunctions(self):
         functions = inspect.getmembers(mod, inspect.isfunction)
         self.assertEqual(functions, [('eggs', mod.eggs),
+                                     ('lobbest', mod.lobbest),
                                      ('spam', mod.spam)])
 
     @unittest.skipIf(sys.flags.optimize >= 2,
@@ -393,6 +394,7 @@ class TestRetrievingSourceCode(GetSourceBase):
     def test_getsource(self):
         self.assertSourceEqual(git.abuse, 29, 39)
         self.assertSourceEqual(mod.StupidGit, 21, 50)
+        self.assertSourceEqual(mod.lobbest, 70, 71)
 
     def test_getsourcefile(self):
         self.assertEqual(normcase(inspect.getsourcefile(mod.spam)), modfile)
index 286f2e2c031e4ba0aa9e9c450843a9323398ceba..279cf5c4638ce2aadb06cbf903b4c1bbb8872d52 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -45,6 +45,9 @@ Library
 - Issue #15014: SMTP.auth() and SMTP.login() now support RFC 4954's optional
   initial-response argument to the SMTP AUTH command.
 
+- Issue #24669: Fix inspect.getsource() for 'async def' functions.
+  Patch by Kai Groner.
+
 
 What's New in Python 3.5.0 beta 3?
 ==================================