From e340f1d087098a0564e0e14200a6614e0da3fe61 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Mon, 29 Apr 2024 13:05:57 -0500 Subject: [PATCH] Redirect pudb warnings to built-in console --- pudb/debugger.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/pudb/debugger.py b/pudb/debugger.py index 7ca66bd3..dc06d9ef 100644 --- a/pudb/debugger.py +++ b/pudb/debugger.py @@ -2526,22 +2526,36 @@ def _save_traceback(self, error_info): # {{{ UI enter/exit - def show(self): + def _show(self): if self.show_count == 0: self.screen.start() self.show_count += 1 - def hide(self): + def _hide(self): self.show_count -= 1 if self.show_count == 0: self.screen.stop() def call_with_ui(self, f, *args, **kwargs): - self.show() - try: - return f(*args, **kwargs) - finally: - self.hide() + import warnings + + def myshowwarning( + message, category, filename, lineno, file=None, line=None + ) -> None: + msg = warnings.formatwarning( + message=message, category=category, + filename=filename, lineno=lineno, line=line) + self.add_cmdline_content(msg, "command line error") + + with warnings.catch_warnings(): + warnings.resetwarnings() + warnings.showwarning = myshowwarning + + self._show() + try: + return f(*args, **kwargs) + finally: + self._hide() # }}}