diff options
author | Raymond Hettinger <python@rcn.com> | 2003-01-14 02:19:36 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2003-01-14 02:19:36 (GMT) |
commit | 2d375f78a570dc627daf61df9d12473633055cdf (patch) | |
tree | ad7ea73d0fecfceebc716fbf8efe8b474ff126f1 /Lib/inspect.py | |
parent | 9896ea24f9dd0ad895f2095b5680fafc901fea6f (diff) | |
download | cpython-2d375f78a570dc627daf61df9d12473633055cdf.zip cpython-2d375f78a570dc627daf61df9d12473633055cdf.tar.gz cpython-2d375f78a570dc627daf61df9d12473633055cdf.tar.bz2 |
SF bug #661184: inspect.getsource bug
inspect.getsource would crash with one line definitions like:
def f(x): return x
or
f = lambda x: x
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r-- | Lib/inspect.py | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py index d3fd3ad..77129fd 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -417,7 +417,7 @@ def findsource(object): 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') + pat = re.compile(r'^(\s*def\s)|(.*\slambda(:|\s))') while lnum > 0: if pat.match(lines[lnum]): break lnum = lnum - 1 @@ -508,6 +508,8 @@ def getblock(lines): tokenize.tokenize(ListReader(lines).readline, BlockFinder().tokeneater) except EndOfBlock, eob: return lines[:eob.args[0]] + # Fooling the indent/dedent logic implies a one-line definition + return lines[:1] def getsourcelines(object): """Return a list of source lines and starting line number for an object. |