diff options
author | Guido van Rossum <guido@python.org> | 1998-02-26 17:25:02 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1998-02-26 17:25:02 (GMT) |
commit | 6e73af723cd094c37f7dc4099306c60084c6ecd0 (patch) | |
tree | 30df89caaebe85360ab62183d47488070eeba303 /Lib/traceback.py | |
parent | 2474d685480f437b68e0fbb110b33f7541a4fe1d (diff) | |
download | cpython-6e73af723cd094c37f7dc4099306c60084c6ecd0.zip cpython-6e73af723cd094c37f7dc4099306c60084c6ecd0.tar.gz cpython-6e73af723cd094c37f7dc4099306c60084c6ecd0.tar.bz2 |
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.
Diffstat (limited to 'Lib/traceback.py')
-rw-r--r-- | Lib/traceback.py | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/Lib/traceback.py b/Lib/traceback.py index d579639..7fc209e 100644 --- a/Lib/traceback.py +++ b/Lib/traceback.py @@ -186,16 +186,16 @@ def extract_stack(f=None, limit = None): # with -O on). # Coded by Marc-Andre Lemburg from the example of PyCode_Addr2Line() # in compile.c. +# Revised version by Jim Hugunin to work with JPython too. def tb_lineno(tb): - f = tb.tb_frame - try: - c = f.f_code - tab = c.co_lnotab - line = c.co_firstlineno - stopat = tb.tb_lasti - except AttributeError: - return f.f_lineno + c = tb.tb_frame.f_code + if not hasattr(c, 'co_lnotab'): + return tb.tb_lineno + + tab = c.co_lnotab + line = c.co_firstlineno + stopat = tb.tb_lasti addr = 0 for i in range(0, len(tab), 2): addr = addr + ord(tab[i]) |