Kaydet (Commit) e4e811d6 authored tarafından Yury Selivanov's avatar Yury Selivanov

Issue #24669: Fix inspect.getsource() for 'async def' functions.

Patch by Kai Groner.
üst 036a71bf
...@@ -798,7 +798,7 @@ def findsource(object): ...@@ -798,7 +798,7 @@ def findsource(object):
if not hasattr(object, 'co_firstlineno'): if not hasattr(object, 'co_firstlineno'):
raise OSError('could not find function definition') raise OSError('could not find function definition')
lnum = object.co_firstlineno - 1 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: while lnum > 0:
if pat.match(lines[lnum]): break if pat.match(lines[lnum]): break
lnum = lnum - 1 lnum = lnum - 1
......
...@@ -66,3 +66,6 @@ class FesteringGob(MalodorousPervert, ParrotDroppings): ...@@ -66,3 +66,6 @@ class FesteringGob(MalodorousPervert, ParrotDroppings):
pass pass
def contradiction(self): def contradiction(self):
pass pass
async def lobbest(grenade):
pass
...@@ -336,6 +336,7 @@ class TestRetrievingSourceCode(GetSourceBase): ...@@ -336,6 +336,7 @@ class TestRetrievingSourceCode(GetSourceBase):
def test_getfunctions(self): def test_getfunctions(self):
functions = inspect.getmembers(mod, inspect.isfunction) functions = inspect.getmembers(mod, inspect.isfunction)
self.assertEqual(functions, [('eggs', mod.eggs), self.assertEqual(functions, [('eggs', mod.eggs),
('lobbest', mod.lobbest),
('spam', mod.spam)]) ('spam', mod.spam)])
@unittest.skipIf(sys.flags.optimize >= 2, @unittest.skipIf(sys.flags.optimize >= 2,
...@@ -393,6 +394,7 @@ class TestRetrievingSourceCode(GetSourceBase): ...@@ -393,6 +394,7 @@ class TestRetrievingSourceCode(GetSourceBase):
def test_getsource(self): def test_getsource(self):
self.assertSourceEqual(git.abuse, 29, 39) self.assertSourceEqual(git.abuse, 29, 39)
self.assertSourceEqual(mod.StupidGit, 21, 50) self.assertSourceEqual(mod.StupidGit, 21, 50)
self.assertSourceEqual(mod.lobbest, 70, 71)
def test_getsourcefile(self): def test_getsourcefile(self):
self.assertEqual(normcase(inspect.getsourcefile(mod.spam)), modfile) self.assertEqual(normcase(inspect.getsourcefile(mod.spam)), modfile)
......
...@@ -45,6 +45,9 @@ Library ...@@ -45,6 +45,9 @@ Library
- Issue #15014: SMTP.auth() and SMTP.login() now support RFC 4954's optional - Issue #15014: SMTP.auth() and SMTP.login() now support RFC 4954's optional
initial-response argument to the SMTP AUTH command. 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? What's New in Python 3.5.0 beta 3?
================================== ==================================
......
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