[traceback] Make _rich_traceback_guard more consistent with _rich_traceback_omit

This commit is contained in:
Olivier Philippon 2022-04-26 13:43:41 +01:00
parent 740b89f49a
commit f0ca6ff2bc
2 changed files with 4 additions and 3 deletions

View file

@ -367,7 +367,7 @@ class Traceback:
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 "?",
@ -385,7 +385,7 @@ class Traceback:
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)

View file

@ -326,7 +326,8 @@ def test_rich_traceback_omit_optional_local_flag(
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():