diff -r 4ffa41843837 py/_code/source.py --- a/py/_code/source.py Sun Oct 21 23:35:10 2012 -0600 +++ b/py/_code/source.py Mon Oct 22 16:25:14 2012 +0200 @@ -118,7 +118,7 @@ # 1. find the start of the statement from codeop import compile_command end = None - for start in range(lineno, -1, -1): + for start in range(lineno, -1, max(-1, lineno - 10)): if assertion: line = self.lines[start] # the following lines are not fully tested, change with care @@ -135,9 +135,9 @@ compile_command(trysource) except (SyntaxError, OverflowError, ValueError): continue - + # 2. find the end of the statement - for end in range(lineno+1, len(self)+1): + for end in range(lineno+1, min(len(self)+1, lineno + 10)): trysource = self[start:end] if trysource.isparseable(): return start, end