Exception Attributes

BaseException.__suppress_context__ — exception attribute

Read or set the flag controlling default display of implicit exception context. It does not remove the context object. An explicit non-None cause still appears in standard traceback formatting regardless of this flag. Prefer raise ... from None when intentionally hiding implicit context.

Formal Syntax & Structure

python syntaxpython
error.__suppress_context__

Return Value

bool

Whether implicit context display is suppressed.

Working Example

Example Snippetpython
try:    try:        int("bad")    except ValueError as original:        raise RuntimeError("configuration") from Noneexcept RuntimeError as error:    print(error.__suppress_context__)    print(type(error.__context__).__name__)
Python Reference