From e4e811d65b51478392a7c69e83b38c6930012eb7 Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Tue, 21 Jul 2015 19:01:52 +0300 Subject: [PATCH] Issue #24669: Fix inspect.getsource() for 'async def' functions. Patch by Kai Groner. --- Lib/inspect.py | 2 +- Lib/test/inspect_fodder.py | 3 +++ Lib/test/test_inspect.py | 2 ++ Misc/NEWS | 3 +++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Lib/inspect.py b/Lib/inspect.py index 42f24cddba8..4c1ac1f283d 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)|(.*(? 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 6f0cad942d3..068d8258b92 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 8e0e73cf007..e6208935a7d 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) diff --git a/Misc/NEWS b/Misc/NEWS index 286f2e2c031..279cf5c4638 100644 --- 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? ==================================