[pypy-commit] pypy py3.5: don't crash if we read less lines than co_firstlineno (it can show up when trying to get the source of some half-builtin function in pypy)
arigo
pypy.commits at gmail.com
Tue Feb 21 05:32:28 EST 2017
Author: Armin Rigo <arigo at tunes.org>
Branch: py3.5
Changeset: r90252:db9d87141352
Date: 2017-02-21 11:31 +0100
http://bitbucket.org/pypy/pypy/changeset/db9d87141352/
Log: don't crash if we read less lines than co_firstlineno (it can show
up when trying to get the source of some half-builtin function in
pypy)
diff --git a/lib-python/3/inspect.py b/lib-python/3/inspect.py
--- a/lib-python/3/inspect.py
+++ b/lib-python/3/inspect.py
@@ -797,7 +797,7 @@
if iscode(object):
if not hasattr(object, 'co_firstlineno'):
raise OSError('could not find function definition')
- lnum = object.co_firstlineno - 1
+ lnum = min(object.co_firstlineno, len(lines)) - 1
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
More information about the pypy-commit
mailing list