[prev in list] [next in list] [prev in thread] [next in thread]
List: python-bugs-list
Subject: [issue24078] inspect.getsourcelines ignores context and returns wrong line #
From: Siming Yuan <report () bugs ! python ! org>
Date: 2015-04-29 23:08:48
Message-ID: 1430348928.98.0.0978970784211.issue24078 () psf ! upfronthosting ! co ! za
[Download RAW message or body]
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@bugs.python.org>
<http://bugs.python.org/issue24078>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/python-bugs-list%40marc.info
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic