Skip to content

Commit

Permalink
[traceback] Make _rich_traceback_guard more consistent with `_rich_…
Browse files Browse the repository at this point in the history
…traceback_omit`
  • Loading branch information
Olivier Philippon committed Apr 26, 2022
1 parent 740b89f commit f0ca6ff
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions rich/traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def safe_str(_object: Any) -> str:
if filename and not filename.startswith("<"):
if not os.path.isabs(filename):
filename = os.path.join(_IMPORT_CWD, filename)
if frame_summary.f_locals.get("_rich_traceback_omit", False) is True:
if frame_summary.f_locals.get("_rich_traceback_omit", False):
continue
frame = Frame(
filename=filename or "?",
Expand All @@ -385,7 +385,7 @@ def safe_str(_object: Any) -> str:
else None,
)
append(frame)
if "_rich_traceback_guard" in frame_summary.f_locals:
if frame_summary.f_locals.get("_rich_traceback_guard", False):
del stack.frames[:]

cause = getattr(exc_value, "__cause__", None)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,8 @@ def level1():
return level2()

def level2():
_rich_traceback_omit = rich_traceback_omit_for_level2
# true-ish values are enough to trigger the opt-out:
_rich_traceback_omit = 1 if rich_traceback_omit_for_level2 else 0
return level3()

def level3():
Expand Down

0 comments on commit f0ca6ff

Please sign in to comment.