Skip to content

Commit

Permalink
Redirect pudb warnings to built-in console
Browse files Browse the repository at this point in the history
  • Loading branch information
inducer committed Apr 29, 2024
1 parent edc0a42 commit e340f1d
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions pudb/debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

# }}}

Expand Down

0 comments on commit e340f1d

Please sign in to comment.