New submission from daniel hahler <python-b...@thequod.de>:
Given: ``` class BadRepr: def __repr__(self): raise Exception('repr_exc') obj = BadRepr() __import__('pdb').set_trace() ``` ``` (Pdb) p obj (Pdb) pp obj (Pdb) ``` Possible patch - clumsy due to `self._getval` both printing any error already, and raising the exception: ``` diff --git i/Lib/pdb.py w/Lib/pdb.py index f5d33c27fc..59a419d961 100755 --- i/Lib/pdb.py +++ w/Lib/pdb.py @@ -1177,18 +1177,28 @@ def do_p(self, arg): Print the value of the expression. """ try: - self.message(repr(self._getval(arg))) + val = self._getval(arg) except: - pass + return + try: + self.message(repr(val)) + except: + exc_info = sys.exc_info()[:2] + self.error(traceback.format_exception_only(*exc_info)[-1].strip()) def do_pp(self, arg): """pp expression Pretty-print the value of the expression. """ try: - self.message(pprint.pformat(self._getval(arg))) + val = self._getval(arg) except: - pass + return + try: + self.message(pprint.pformat(val)) + except: + exc_info = sys.exc_info()[:2] + self.error(traceback.format_exception_only(*exc_info)[-1].strip()) complete_print = _complete_expression complete_p = _complete_expression ``` ---------- components: Library (Lib) messages: 343306 nosy: blueyed priority: normal severity: normal status: open title: pdb: do_p and do_pp swallow exceptions from __repr__ type: behavior versions: Python 3.7, Python 3.8, Python 3.9 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue37022> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com