diff options
author | Yury Selivanov <yselivanov@sprymix.com> | 2015-07-21 16:01:52 (GMT) |
---|---|---|
committer | Yury Selivanov <yselivanov@sprymix.com> | 2015-07-21 16:01:52 (GMT) |
commit | e4e811d65b51478392a7c69e83b38c6930012eb7 (patch) | |
tree | 36228ce64ec8a50737933259ac9aa33cffd68faf /Lib | |
parent | 036a71bf25b84fab72b023eaf9591e9c16ae2c52 (diff) | |
download | cpython-e4e811d65b51478392a7c69e83b38c6930012eb7.zip cpython-e4e811d65b51478392a7c69e83b38c6930012eb7.tar.gz cpython-e4e811d65b51478392a7c69e83b38c6930012eb7.tar.bz2 |
Issue #24669: Fix inspect.getsource() for 'async def' functions.
Patch by Kai Groner.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/inspect.py | 2 | ||||
-rw-r--r-- | Lib/test/inspect_fodder.py | 3 | ||||
-rw-r--r-- | Lib/test/test_inspect.py | 2 |
3 files changed, 6 insertions, 1 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py index 42f24cd..4c1ac1f 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -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 diff --git a/Lib/test/inspect_fodder.py b/Lib/test/inspect_fodder.py index 6f0cad9..068d825 100644 --- a/Lib/test/inspect_fodder.py +++ b/Lib/test/inspect_fodder.py @@ -66,3 +66,6 @@ class FesteringGob(MalodorousPervert, ParrotDroppings): pass def contradiction(self): pass + +async def lobbest(grenade): + pass diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index 8e0e73c..e620893 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -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) |