summaryrefslogtreecommitdiffstats
path: root/Lib/inspect.py
diff options
context:
space:
mode:
authorKa-Ping Yee <ping@zesty.ca>2001-03-10 09:31:55 (GMT)
committerKa-Ping Yee <ping@zesty.ca>2001-03-10 09:31:55 (GMT)
commita6e59719ec611a012227719e7d3ed1730601cca9 (patch)
treeeb90351321ef30310ab824a10d3fde3216e03935 /Lib/inspect.py
parent63085d4d1e7d705a7d38bf1a8dc7457ea58e33a2 (diff)
downloadcpython-a6e59719ec611a012227719e7d3ed1730601cca9.zip
cpython-a6e59719ec611a012227719e7d3ed1730601cca9.tar.gz
cpython-a6e59719ec611a012227719e7d3ed1730601cca9.tar.bz2
Fix findsource() to work for derived classes.
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r--Lib/inspect.py10
1 files changed, 5 insertions, 5 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py
index deccabd..a7c7859 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -27,7 +27,7 @@ Here are some of the useful functions provided by this module:
__author__ = 'Ka-Ping Yee <ping@lfw.org>'
__date__ = '1 Jan 2001'
-import sys, os, types, string, dis, imp, tokenize
+import sys, os, types, string, re, dis, imp, tokenize
# ----------------------------------------------------------- type-checking
def ismodule(object):
@@ -259,10 +259,9 @@ def findsource(object):
if isclass(object):
name = object.__name__
- matches = (['class', name], ['class', name + ':'])
+ pat = re.compile(r'^\s*class\s*' + name + r'\b')
for i in range(len(lines)):
- if string.split(lines[i])[:2] in matches:
- return lines, i
+ if pat.match(lines[i]): return lines, i
else: raise IOError, 'could not find class definition'
if ismethod(object):
@@ -277,8 +276,9 @@ 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')
while lnum > 0:
- if string.split(lines[lnum])[:1] == ['def']: break
+ if pat.match(lines[lnum]): break
lnum = lnum - 1
return lines, lnum