Skip to content

tarfile.TarFile.next() adds an unnecessary traceback frame when reraising exceptions #149760

Description

@lpyu001

description:

https://gist.github.com/devdanzin/f8af359770ff200eac8474de5644be82

tarfile.TarFile.next() currently reraises non-zlib exceptions with raise e
inside its generic exception handler:

except Exception as e:
    try:
        import zlib
        if isinstance(e, zlib.error):
            raise ReadError(f'zlib error: {e}') from None
        else:
            raise e
    except ImportError:
        raise e

Using raise e adds an extra traceback frame at the re-raise site. A bare
raise would keep the traceback cleaner while preserving the original exception
and its traceback.

CPython versions tested on:

3.14, CPython main branch

Operating systems tested on:

Windows

Linked PRs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions