[issue24078] inspect.getsourcelines ignores context and returns wrong line #
Siming Yuan
report at bugs.python.org
Thu Apr 30 01:08:48 CEST 2015
Siming Yuan added the comment:
according to inspect.py line 675 - this is only a best effort.
is this intended?
inspect.py @ 672
if isclass(object):
name = object.__name__
pat = re.compile(r'^(\s*)class\s*' + name + r'\b')
# make some effort to find the best matching class definition:
# use the one with the least indentation, which is the one
# that's most probably not inside a function definition.
candidates = []
for i in range(len(lines)):
match = pat.match(lines[i])
if match:
# if it's at toplevel, it's already the best one
if lines[i][0] == 'c':
return lines, i
# else add whitespace to candidate list
candidates.append((match.group(1), i))
if candidates:
# this will sort by whitespace, and by line number,
# less whitespace first
candidates.sort()
return lines, candidates[0][1]
else:
raise OSError('could not find class definition')
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue24078>
_______________________________________
More information about the Python-bugs-list
mailing list