]> granicus.if.org Git - python/commitdiff
Remove sys.exc_type, sys.exc_value, sys.exc_traceback
authorNeal Norwitz <nnorwitz@gmail.com>
Fri, 17 Mar 2006 05:49:33 +0000 (05:49 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Fri, 17 Mar 2006 05:49:33 +0000 (05:49 +0000)
16 files changed:
Demo/classes/Complex.py
Demo/pdist/server.py
Demo/sockets/gopher.py
Doc/api/exceptions.tex
Doc/api/intro.tex
Doc/ext/extending.tex
Doc/lib/libtraceback.tex
Doc/ref/ref7.tex
Lib/SimpleXMLRPCServer.py
Lib/idlelib/WindowList.py
Lib/lib-tk/Tkinter.py
Lib/traceback.py
Mac/Tools/IDE/PyDebugger.py
Mac/Tools/IDE/PyEdit.py
Python/sysmodule.c
Tools/faqwiz/faqw.py

index 2b306ad5eadf7c41b5676cc85fa3d7fce0f1e547..a77989750f98d693310ebaf3a287d0b6c64bfa2c 100755 (executable)
@@ -233,7 +233,7 @@ def checkop(expr, a, b, value, fuzz = 1e-6):
     try:
         result = eval(expr)
     except:
-        result = sys.exc_type
+        result = sys.exc_info()[0]
     print '->', result
     if isinstance(result, str) or isinstance(value, str):
         ok = (result == value)
index e692eea7ffc63f1b659ee5cebd600c620ee21994..01b3249371509a9663fb4d4f1a6681d6c0f2d86d 100755 (executable)
@@ -83,7 +83,7 @@ class Server:
                 method = getattr(self, methodname)
                 reply = (None, apply(method, args), id)
         except:
-            reply = (sys.exc_type, sys.exc_value, id)
+            reply = (sys.exc_info()[:2], id)
         if id < 0 and reply[:2] == (None, None):
             if self._verbose > 1: print "Suppress reply"
             return 1
index cd76659365a3fcc0ce6cd3d5b307353cead4e150..34bcdf0cc21f47eb8d94e170e66143b0b91dc831 100755 (executable)
@@ -191,7 +191,8 @@ def browse_menu(selector, host, port):
             try:
                 browserfunc(i_selector, i_host, i_port)
             except (IOError, socket.error):
-                print '***', sys.exc_type, ':', sys.exc_value
+                t, v, tb = sys.exc_info()
+                print '***', t, ':', v
         else:
             print 'Unsupported object type'
 
index c4727f2f93de6a7471b5e74042d55b400c8cce09..62f713bc6f70a3678179a9a7809516c6b305e483 100644 (file)
@@ -23,12 +23,9 @@ carefully propagated, additional calls into the Python/C API may not
 behave as intended and may fail in mysterious ways.
 
 The error indicator consists of three Python objects corresponding to
-\withsubitem{(in module sys)}{
-  \ttindex{exc_type}\ttindex{exc_value}\ttindex{exc_traceback}}
-the Python variables \code{sys.exc_type}, \code{sys.exc_value} and
-\code{sys.exc_traceback}.  API functions exist to interact with the
-error indicator in various ways.  There is a separate error indicator
-for each thread.
+the result of \code{sys.exc_info()}.  API functions exist to interact
+with the error indicator in various ways.  There is a separate
+error indicator for each thread.
 
 % XXX Order of these should be more thoughtful.
 % Either alphabetical or some kind of structure.
index d84b654757669ef9320012108fca798cd0069397..608d56244a99620f57fa525480fcae264dea3b68 100644 (file)
@@ -400,15 +400,12 @@ exception state.
 The full exception state consists of three objects (all of which can 
 be \NULL): the exception type, the corresponding exception 
 value, and the traceback.  These have the same meanings as the Python
-\withsubitem{(in module sys)}{
-  \ttindex{exc_type}\ttindex{exc_value}\ttindex{exc_traceback}}
-objects \code{sys.exc_type}, \code{sys.exc_value}, and
-\code{sys.exc_traceback}; however, they are not the same: the Python
+result of \code{sys.exc_info()}; however, they are not the same: the Python
 objects represent the last exception being handled by a Python 
 \keyword{try} \ldots\ \keyword{except} statement, while the C level
 exception state only exists while an exception is being passed on
 between C functions until it reaches the Python bytecode interpreter's 
-main loop, which takes care of transferring it to \code{sys.exc_type}
+main loop, which takes care of transferring it to \code{sys.exc_info()}
 and friends.
 
 Note that starting with Python 1.5, the preferred, thread-safe way to 
index 7016f94d4cefda1981ecb2a931ec7569ffe81536..0e2fd14b9ee5fc46d5f8b17a7d945649bb5c88f1 100644 (file)
@@ -120,9 +120,8 @@ variable is \NULL{} no exception has occurred.  A second global
 variable stores the ``associated value'' of the exception (the second
 argument to \keyword{raise}).  A third variable contains the stack
 traceback in case the error originated in Python code.  These three
-variables are the C equivalents of the Python variables
-\code{sys.exc_type}, \code{sys.exc_value} and \code{sys.exc_traceback} (see
-the section on module \module{sys} in the
+variables are the C equivalents of the result in Python of 
+\method{sys.exc_info()} (see the section on module \module{sys} in the
 \citetitle[../lib/lib.html]{Python Library Reference}).  It is
 important to know about them to understand how errors are passed
 around.
index b7f61ace981197f8541a47e7debd68fd9300ff02..80dc423c08915a47f92ded399b2f2555c94ea3b1 100644 (file)
@@ -12,9 +12,8 @@ when you want to print stack traces under program control, such as in a
 ``wrapper'' around the interpreter.
 
 The module uses traceback objects --- this is the object type that is
-stored in the variables \code{sys.exc_traceback} (deprecated) and
-\code{sys.last_traceback} and returned as the third item from
-\function{sys.exc_info()}.
+stored in the \code{sys.last_traceback} variable and returned
+as the third item from \function{sys.exc_info()}.
 \obindex{traceback}
 
 The module defines the following functions:
@@ -41,11 +40,7 @@ with a caret indicating the approximate position of the error.
 \end{funcdesc}
 
 \begin{funcdesc}{print_exc}{\optional{limit\optional{, file}}}
-This is a shorthand for \code{print_exception(sys.exc_type,
-sys.exc_value, sys.exc_traceback, \var{limit}, \var{file})}.  (In
-fact, it uses \function{sys.exc_info()} to retrieve the same
-information in a thread-safe way instead of using the deprecated
-variables.)
+This is a shorthand for \code{print_exception(*\function{sys.exc_info()}}.
 \end{funcdesc}
 
 \begin{funcdesc}{format_exc}{\optional{limit}}
index 4ae6040fbdccca4eef908b1ffcbabdb522232f79..90627a485ff0dd64edbb727d8c158dcc2ecdf3f9 100644 (file)
@@ -250,21 +250,15 @@ occurs in the try clause of the inner handler, the outer handler will
 not handle the exception.)
 
 Before an except clause's suite is executed, details about the
-exception are assigned to three variables in the
-\module{sys}\refbimodindex{sys} module: \code{sys.exc_type} receives
-the object identifying the exception; \code{sys.exc_value} receives
-the exception's parameter; \code{sys.exc_traceback} receives a
+exception are stored in the \module{sys}\refbimodindex{sys} module
+and can be access via \function{sys.exc_info()}. \function{sys.exc_info()}
+returns a 3-tuple consisting of: \code{exc_type} receives
+the object identifying the exception; \code{exc_value} receives
+the exception's parameter; \code{exc_traceback} receives a
 traceback object\obindex{traceback} (see section~\ref{traceback})
 identifying the point in the program where the exception occurred.
-These details are also available through the \function{sys.exc_info()}
-function, which returns a tuple \code{(\var{exc_type}, \var{exc_value},
-\var{exc_traceback})}.  Use of the corresponding variables is
-deprecated in favor of this function, since their use is unsafe in a
-threaded program.  As of Python 1.5, the variables are restored to
-their previous values (before the call) when returning from a function
-that handled an exception.
-\withsubitem{(in module sys)}{\ttindex{exc_type}
-  \ttindex{exc_value}\ttindex{exc_traceback}}
+\function{sys.exc_info()} values are restored to their previous values
+(before the call) when returning from a function that handled an exception.
 
 The optional \keyword{else} clause is executed if and when control
 flows off the end of the \keyword{try} clause.\footnote{
index 052a8e4aed8607d5adb9d03eea07848f2f43dc88..156c2ba7aee2b0bef5d0e79e08a0b6a45a2c6aef 100644 (file)
@@ -261,7 +261,7 @@ class SimpleXMLRPCDispatcher:
         except:
             # report exception back to server
             response = xmlrpclib.dumps(
-                xmlrpclib.Fault(1, "%s:%s" % (sys.exc_type, sys.exc_value)),
+                xmlrpclib.Fault(1, "%s:%s" % sys.exc_info()[:2]),
                 encoding=self.encoding, allow_none=self.allow_none,
                 )
 
@@ -362,7 +362,7 @@ class SimpleXMLRPCDispatcher:
             except:
                 results.append(
                     {'faultCode' : 1,
-                     'faultString' : "%s:%s" % (sys.exc_type, sys.exc_value)}
+                     'faultString' : "%s:%s" % sys.exc_info()[:2]}
                     )
         return results
 
index 658502b20b02f93fccf0010969c8705ffbf0499a..d0123d88ba41be3b6ca326126097c1a7a0f9aadd 100644 (file)
@@ -45,8 +45,8 @@ class WindowList:
             try:
                 callback()
             except:
-                print "warning: callback failed in WindowList", \
-                      sys.exc_type, ":", sys.exc_value
+               t, v, tb = sys.exc_info()
+                print "warning: callback failed in WindowList", t, ":", v
 
 registry = WindowList()
 
index 37ddd3a4cb7eacc583593e5dbda71cea26f22f06..d600cd790786358f0989a6ffc23f7e5b64c34ac7 100644 (file)
@@ -1108,7 +1108,7 @@ class Misc:
     def _report_exception(self):
         """Internal function."""
         import sys
-        exc, val, tb = sys.exc_type, sys.exc_value, sys.exc_traceback
+        exc, val, tb = sys.exc_info()
         root = self._root()
         root.report_callback_exception(exc, val, tb)
     def _configure(self, cmd, cnf, kw):
index 497190656f8f12549e66d5c7d940e457d3b5da6a..93a64b7f301951d8ca23fe9784144c3b979c196c 100644 (file)
@@ -203,9 +203,7 @@ def _some_str(value):
 
 
 def print_exc(limit=None, file=None):
-    """Shorthand for 'print_exception(sys.exc_type, sys.exc_value, sys.exc_traceback, limit, file)'.
-    (In fact, it uses sys.exc_info() to retrieve the same information
-    in a thread-safe way.)"""
+    """Shorthand for 'print_exception(*sys.exc_info(), limit, file)'."""
     if file is None:
         file = sys.stderr
     try:
index 5ee92d50201e842da01c3b92ca02c89faa20d6d9..7fbc0f0f0a711c9924da5f08c69b59efe0fc2441 100644 (file)
@@ -105,7 +105,8 @@ class Debugger(bdb.Bdb):
             raise 'spam'
         except:
             pass
-        frame = sys.exc_traceback.tb_frame
+        tb = sys.exc_info()[2]
+        frame = tb.tb_frame
         while frame is not None:
             del frame.f_trace
             frame = frame.f_back
@@ -527,7 +528,7 @@ class Debugger(bdb.Bdb):
                 raise bdb.BdbQuit
         except:
             print 'XXX Exception during debugger interaction.', \
-                            self.formatexception(sys.exc_type, sys.exc_value)
+                            self.formatexception(sys.exc_info[:2])
             import traceback
             traceback.print_exc()
             return self.trace_dispatch
@@ -855,7 +856,8 @@ def startfromhere():
     try:
         raise 'spam'
     except:
-        frame = sys.exc_traceback.tb_frame.f_back
+        tb = sys.exc_info()[2]
+        frame = tb.tb_frame.f_back
     d.start(frame)
 
 def startfrombottom():
@@ -876,7 +878,8 @@ def _getbottomframe():
         raise 'spam'
     except:
         pass
-    frame = sys.exc_traceback.tb_frame
+    tb = sys.exc_info()[2]
+    frame = tb.tb_frame
     while 1:
         if frame.f_code.co_name == 'mainloop' or frame.f_back is None:
             break
index 88c72aca492fc8d6c905b22e6845dad3e491c566..56f3f8da93429aa7329062670b42f179d043701f 100644 (file)
@@ -1212,7 +1212,7 @@ def execstring(pytext, globals, locals, filename="<string>", debugging=0,
     except:
         if debugging:
             sys.settrace(None)
-            PyDebugger.postmortem(sys.exc_type, sys.exc_value, sys.exc_traceback)
+            PyDebugger.postmortem(*sys.exc_info())
             return
         else:
             tracebackwindow.traceback(1, filename)
@@ -1289,7 +1289,6 @@ class _EditorDefaultSettings:
         settings = FontSettings.FontDialog(self.fontsettings, self.tabsettings)
         if settings:
             self.fontsettings, self.tabsettings = settings
-            sys.exc_traceback = None
             self.w.fonttext.set(self.template % (self.fontsettings[0], self.fontsettings[2]))
 
     def close(self):
@@ -1327,7 +1326,6 @@ def geteditorprefs():
         fontsettings = prefs.pyedit.fontsettings = ("Geneva", 0, 10, (0, 0, 0))
         tabsettings = prefs.pyedit.tabsettings = (8, 1)
         windowsize = prefs.pyedit.windowsize = (500, 250)
-        sys.exc_traceback = None
     return fontsettings, tabsettings, windowsize
 
 def seteditorprefs(fontsettings, tabsettings, windowsize):
index dfa6ac84d91f2aaa7d37b4fb3174a51a1c82b22c..875f73f946cce59c4e1d453245a3311e52d206bc 100644 (file)
@@ -179,10 +179,6 @@ sys_exc_clear(PyObject *self, PyObject *noargs)
        Py_XDECREF(tmp_type);
        Py_XDECREF(tmp_value);
        Py_XDECREF(tmp_tb);
-       /* For b/w compatibility */
-       PySys_SetObject("exc_type", Py_None);
-       PySys_SetObject("exc_value", Py_None);
-       PySys_SetObject("exc_traceback", Py_None);
        Py_INCREF(Py_None);
        return Py_None;
 }
index 36c52e9af99a20e0efef01999ac75655039176d3..a26e0d60eedab3496f0cbc2264a865070d7db6dc 100755 (executable)
@@ -27,7 +27,7 @@ try:
 except SystemExit, n:
     sys.exit(n)
 except:
-    t, v, tb = sys.exc_type, sys.exc_value, sys.exc_traceback
+    t, v, tb = sys.exc_info()
     print
     import cgi
     cgi.print_exception(t, v, tb)