[issue22355] inconsistent results with inspect.getsource() / inspect.getsourcelines()

Iestyn Elfick report at bugs.python.org
Sun Sep 7 17:42:25 CEST 2014


Iestyn Elfick added the comment:

Possible fix:

--- /usr/lib64/python3.3/inspect.py     2014-06-30 19:21:52.000000000 +0200
+++ inspect.py  2014-09-07 17:41:29.463936079 +0200
@@ -600,7 +600,8 @@
         if not hasattr(object, 'co_firstlineno'):
             raise IOError('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|class)\s)|(.*(?<!\w)lambda(:|\s))|^(\s*@)')
         while lnum > 0:
             if pat.match(lines[lnum]): break
             lnum = lnum - 1

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22355>
_______________________________________


More information about the Python-bugs-list mailing list