Skip to content

__tracebackhide__ does not work with chained exceptions #1904

@The-Compiler

Description

@The-Compiler

On Python 3, with this code:

def bar():
    __tracebackhide__ = True
    raise ValueError

def assert_foo():
    __tracebackhide__ = True
    bar()

def test_foo():
    assert_foo()

I get a nice cleaned up traceback as I'd expect:

_____________________ test_foo ______________________

    def test_foo():
>       assert_foo()
E       ValueError

tbh.py:10: ValueError

However, if I re-raise the exception:

def bar():
    __tracebackhide__ = True
    raise ValueError

def assert_foo():
    __tracebackhide__ = True
    try:
        bar()
    except ValueError:
        raise TypeError

def test_foo():
    assert_foo()

The traceback gets quite verbose:

_____________________ test_foo ______________________

    def assert_foo():
        __tracebackhide__ = True
        try:
>           bar()

tbh.py:8: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def bar():
        __tracebackhide__ = True
>       raise ValueError
E       ValueError

tbh.py:3: ValueError

During handling of the above exception, another exception occurred:

    def test_foo():
>       assert_foo()
E       TypeError

tbh.py:13: TypeError

cc @roolebo

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: tracebacksrelated to displaying and handling of tracebackstype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions