]> granicus.if.org Git - python/commitdiff
Issue 1106316. post_mortem()'s parameter, traceback, is now
authorFacundo Batista <facundobatista@gmail.com>
Sat, 8 Mar 2008 16:50:27 +0000 (16:50 +0000)
committerFacundo Batista <facundobatista@gmail.com>
Sat, 8 Mar 2008 16:50:27 +0000 (16:50 +0000)
optional: it defaults to the traceback of the exception that is currently
being handled.

Doc/library/pdb.rst
Lib/pdb.py
Misc/NEWS

index 2b28ae0ef52e7e5c9d6740f0e2a24079553b3b34..0d2a936e0a1b359b5dd43ca58ac857997dae3b0c 100644 (file)
@@ -107,9 +107,12 @@ slightly different way:
    being debugged (e.g. when an assertion fails).
 
 
-.. function:: post_mortem(traceback)
+.. function:: post_mortem([traceback])
 
-   Enter post-mortem debugging of the given *traceback* object.
+   Enter post-mortem debugging of the given *traceback* object.  If no 
+   *traceback* is given, it uses the one of the exception that is currently
+   being handled (an exception must be being handled if the default is to be
+   used).
 
 
 .. function:: pm()
index 8da23d86fe44a3ff528c6d074bbe80a32188a262..82b52a3852efa9c0ff030b0ef8a451c3fc7ead8c 100755 (executable)
@@ -1198,7 +1198,16 @@ def set_trace():
 
 # Post-Mortem interface
 
-def post_mortem(t):
+def post_mortem(t=None):
+    # handling the default
+    if t is None:
+        # sys.exc_info() returns (type, value, traceback) if an exception is
+        # being handled, otherwise it returns None
+        t = sys.exc_info()[2]
+        if t is None:
+            raise ValueError("A valid traceback must be passed if no "
+                                               "exception is being handled")
+
     p = Pdb()
     p.reset()
     while t.tb_next is not None:
index 26b8b79182ab0810c2647c9ff467aff2812367ed..bd3a6cca0dc682740a8c7329d2bb777bac49356a 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -21,6 +21,11 @@ Core and builtins
 Library
 -------
 
+- Issue #1106316: pdb.post_mortem()'s parameter, "traceback", is now
+  optional: it defaults to the traceback of the exception that is currently
+  being handled (is mandatory to be in the middle of an exception, otherwise
+  it raises ValueError).
+
 - Issue #1193577: A .shutdown() method has been added to SocketServers
   which terminates the .serve_forever() loop.