Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ def preloop(self):
displaying = self.displaying.get(self.curframe)
if displaying:
for expr, oldvalue in displaying.items():
newvalue = self._getval_except(expr)
newvalue, _ = self._getval_except(expr)
# check for identity first; this prevents custom __eq__ to
# be called at every loop, and also prevents instances whose
# fields are changed to be displayed
Expand Down Expand Up @@ -1246,13 +1246,12 @@ def _getval(self, arg):
def _getval_except(self, arg, frame=None):
try:
if frame is None:
return eval(arg, self.curframe.f_globals, self.curframe_locals)
return eval(arg, self.curframe.f_globals, self.curframe_locals), None
else:
return eval(arg, frame.f_globals, frame.f_locals)
except:
exc_info = sys.exc_info()[:2]
err = traceback.format_exception_only(*exc_info)[-1].strip()
return _rstr('** raised %s **' % err)
return eval(arg, frame.f_globals, frame.f_locals), None
except BaseException as exc:
err = traceback.format_exception_only(exc)[-1].strip()
return _rstr('** raised %s **' % err), exc

def _error_exc(self):
exc_info = sys.exc_info()[:2]
Expand Down Expand Up @@ -1437,13 +1436,19 @@ def do_display(self, arg):
Without expression, list all display expressions for the current frame.
"""
if not arg:
self.message('Currently displaying:')
for item in self.displaying.get(self.curframe, {}).items():
self.message('%s: %r' % item)
if self.displaying:
self.message('Currently displaying:')
for item in self.displaying.get(self.curframe, {}).items():
self.message('%s: %r' % item)
else:
self.message('No expression is being displayed')
else:
val = self._getval_except(arg)
self.displaying.setdefault(self.curframe, {})[arg] = val
self.message('display %s: %r' % (arg, val))
val, exc = self._getval_except(arg)
if isinstance(exc, SyntaxError):
self.message(f'Unable to display "{arg}": SyntaxError')
else:
self.displaying.setdefault(self.curframe, {})[arg] = val
self.message('display %s: %r' % (arg, val))

complete_display = _complete_expression

Expand Down
6 changes: 6 additions & 0 deletions Lib/test/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,8 @@ def test_pdb_display_command():
... a = 4

>>> with PdbTestInput([ # doctest: +ELLIPSIS
... 'display +',
... 'display',
... 'display a',
... 'n',
... 'display',
Expand All @@ -600,6 +602,10 @@ def test_pdb_display_command():
... test_function()
> <doctest test.test_pdb.test_pdb_display_command[0]>(4)test_function()
-> a = 1
(Pdb) display +
Unable to display "+": SyntaxError
(Pdb) display
No expression is being displayed
(Pdb) display a
display a: 0
(Pdb) n
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added SyntaxError check on :mod:`pdb`'s display command