Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6e73af7

Browse files
committed
New version of tb_lineno(), this time *not* using try-except, to avoid
disturbing the current exception, and returning tb.tb_lineno, which is the line number of thr traceback, rather than the current line number. By Jim Hugunin.
1 parent 2474d68 commit 6e73af7

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

Lib/traceback.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,16 @@ def extract_stack(f=None, limit = None):
186186
# with -O on).
187187
# Coded by Marc-Andre Lemburg from the example of PyCode_Addr2Line()
188188
# in compile.c.
189+
# Revised version by Jim Hugunin to work with JPython too.
189190

190191
def tb_lineno(tb):
191-
f = tb.tb_frame
192-
try:
193-
c = f.f_code
194-
tab = c.co_lnotab
195-
line = c.co_firstlineno
196-
stopat = tb.tb_lasti
197-
except AttributeError:
198-
return f.f_lineno
192+
c = tb.tb_frame.f_code
193+
if not hasattr(c, 'co_lnotab'):
194+
return tb.tb_lineno
195+
196+
tab = c.co_lnotab
197+
line = c.co_firstlineno
198+
stopat = tb.tb_lasti
199199
addr = 0
200200
for i in range(0, len(tab), 2):
201201
addr = addr + ord(tab[i])

0 commit comments

Comments
 (0)