]> granicus.if.org Git - python/commitdiff
New version of tb_lineno(), this time *not* using try-except, to avoid
authorGuido van Rossum <guido@python.org>
Thu, 26 Feb 1998 17:25:02 +0000 (17:25 +0000)
committerGuido van Rossum <guido@python.org>
Thu, 26 Feb 1998 17:25:02 +0000 (17:25 +0000)
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.

Lib/traceback.py

index d57963932afb9edcde8550fa2a136f3b80b3db21..7fc209ee143f3b6bd76918e866596619c8f715be 100644 (file)
@@ -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])