Skip to content

Commit

Permalink
fix: Make show_vars behave properly
Browse files Browse the repository at this point in the history
  • Loading branch information
skorokithakis committed May 18, 2017
1 parent aa46f07 commit 6990be9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 6 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
6 changes: 3 additions & 3 deletions tbvaccine/tbv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

0 comments on commit 6990be9

Please sign in to comment.