[Python-checkins] r82263 - in python/branches/py3k: Doc/library/pdb.rst Lib/pdb.doc Lib/pdb.py Misc/NEWS

georg.brandl python-checkins at python.org
Sun Jun 27 12:37:48 CEST 2010


Author: georg.brandl
Date: Sun Jun 27 12:37:48 2010
New Revision: 82263

Log:
#9064: accept number of frames for "up" and "down" commands in pdb.

Modified:
   python/branches/py3k/Doc/library/pdb.rst
   python/branches/py3k/Lib/pdb.doc
   python/branches/py3k/Lib/pdb.py
   python/branches/py3k/Misc/NEWS

Modified: python/branches/py3k/Doc/library/pdb.rst
==============================================================================
--- python/branches/py3k/Doc/library/pdb.rst	(original)
+++ python/branches/py3k/Doc/library/pdb.rst	Sun Jun 27 12:37:48 2010
@@ -210,11 +210,13 @@
    Print a stack trace, with the most recent frame at the bottom.  An arrow
    indicates the current frame, which determines the context of most commands.
 
-d(own)
-   Move the current frame one level down in the stack trace (to a newer frame).
-
-u(p)
-   Move the current frame one level up in the stack trace (to an older frame).
+d(own) [*count*]
+   Move the current frame *count* (default one) levels down in the stack trace
+   (to a newer frame).
+
+u(p) [*count*]
+   Move the current frame *count* (default one) levels up in the stack trace
+   (to an older frame).
 
 b(reak) [[*filename*:]\ *lineno* | *function*\ [, *condition*]]
    With a *lineno* argument, set a break there in the current file.  With a

Modified: python/branches/py3k/Lib/pdb.doc
==============================================================================
--- python/branches/py3k/Lib/pdb.doc	(original)
+++ python/branches/py3k/Lib/pdb.doc	Sun Jun 27 12:37:48 2010
@@ -68,13 +68,13 @@
         An arrow indicates the "current frame", which determines the
         context of most commands.
 
-d(own)
-        Move the current frame one level down in the stack trace
-        (to a newer frame).
-
-u(p)
-        Move the current frame one level up in the stack trace
-        (to an older frame).
+d(own) [ count ]
+        Move the current frame count (default one) levels down in the
+	stack trace (to a newer frame).
+
+u(p) [ count ]
+        Move the current frame count (default one) levels up in the
+	stack trace (to an older frame).
 
 b(reak) [ ([filename:]lineno | function) [, condition] ]
         With a filename:line number argument, set a break there.  If

Modified: python/branches/py3k/Lib/pdb.py
==============================================================================
--- python/branches/py3k/Lib/pdb.py	(original)
+++ python/branches/py3k/Lib/pdb.py	Sun Jun 27 12:37:48 2010
@@ -618,26 +618,44 @@
     do_w = do_where
     do_bt = do_where
 
+    def _select_frame(self, number):
+        assert 0 <= number < len(self.stack)
+        self.curindex = number
+        self.curframe = self.stack[self.curindex][0]
+        self.curframe_locals = self.curframe.f_locals
+        self.print_stack_entry(self.stack[self.curindex])
+        self.lineno = None
+
     def do_up(self, arg):
         if self.curindex == 0:
             print('*** Oldest frame', file=self.stdout)
+            return
+        try:
+            count = int(arg or 1)
+        except ValueError:
+            print('*** Invalid frame count (%s)' % arg, file=self.stdout)
+            return
+        if count < 0:
+            newframe = 0
         else:
-            self.curindex = self.curindex - 1
-            self.curframe = self.stack[self.curindex][0]
-            self.curframe_locals = self.curframe.f_locals
-            self.print_stack_entry(self.stack[self.curindex])
-            self.lineno = None
+            newframe = max(0, self.curindex - count)
+        self._select_frame(newframe)
     do_u = do_up
 
     def do_down(self, arg):
         if self.curindex + 1 == len(self.stack):
             print('*** Newest frame', file=self.stdout)
+            return
+        try:
+            count = int(arg or 1)
+        except ValueError:
+            print('*** Invalid frame count (%s)' % arg, file=self.stdout)
+            return
+        if count < 0:
+            newframe = len(self.stack) - 1
         else:
-            self.curindex = self.curindex + 1
-            self.curframe = self.stack[self.curindex][0]
-            self.curframe_locals = self.curframe.f_locals
-            self.print_stack_entry(self.stack[self.curindex])
-            self.lineno = None
+            newframe = min(len(self.stack) - 1, self.curindex + count)
+        self._select_frame(newframe)
     do_d = do_down
 
     def do_until(self, arg):

Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Sun Jun 27 12:37:48 2010
@@ -456,6 +456,8 @@
 Library
 -------
 
+- Issue #9064: pdb's "up" and "down" commands now accept an optional argument.
+
 - Issue #9018: os.path.normcase() now raises a TypeError if the argument is
   not ``str`` or ``bytes``.
 


More information about the Python-checkins mailing list