From 6990be9ff2a2f36f0963156f02f99d2b1f14861f Mon Sep 17 00:00:00 2001 From: Stavros Korokithakis Date: Thu, 18 May 2017 03:30:52 +0300 Subject: [PATCH] fix: Make show_vars behave properly --- README.rst | 8 ++++++-- tbvaccine/tbv.py | 6 +++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/README.rst b/README.rst index 3a1f7b9..277ead9 100644 --- a/README.rst +++ b/README.rst @@ -67,6 +67,9 @@ directory, as returned by ``os.getcwd()`` will be used. If ``isolate`` is ``False``, all lines are colorized, and ``code_dir`` is ignored. +If ``show_vars`` is ``False``, variables will not be printed in each stack +frame. + To use it in an ``except`` block:: from tbvaccine import TBVaccine @@ -76,10 +79,11 @@ To use it in an ``except`` block:: print(TBVaccine().format_exc()) -To make it the default way of printing tracebacks, use ``add_hook()``:: +To make it the default way of printing tracebacks, use ``add_hook()`` (which +also accepts any argument the ``TBVaccine`` class does):: import tbvaccine - tbvaccine.add_hook() + tbvaccine.add_hook(isolate=False) 1 / 0 diff --git a/tbvaccine/tbv.py b/tbvaccine/tbv.py index eeccc44..3bb32b9 100644 --- a/tbvaccine/tbv.py +++ b/tbvaccine/tbv.py @@ -68,7 +68,7 @@ def _process_var_line(self, line): """ Process a line of variables in the traceback. """ - if self._show_vars and self._isolate and not self._file_in_dir(): + if self._show_vars is False or (self._isolate and not self._file_in_dir()): # Don't print. return False else: @@ -197,10 +197,10 @@ def format_exc(self): return self._format_tb_string_with_locals(*sys.exc_info()) -def add_hook(): +def add_hook(*args, **kwargs): if not getattr(sys.stderr, 'isatty', lambda: False)(): sys.stderr.write("\n\nNot an interactive session, " "TBVaccine won't pretty print exceptions.\n\n") return - tbv = TBVaccine() + tbv = TBVaccine(*args, **kwargs) sys.excepthook = tbv.print_exception