Skip to content

Suggestion: reset sys.last_traceback using del rather than setting to None #6255

Closed
@mdickinson

Description

@mdickinson

PR #3384 introduced code that resets sys.last_traceback and friends by assigning None to them:

sys.last_type, sys.last_value, sys.last_traceback = (None, None, None)

The normal CPython behaviour here is that once the exception has been cleared, the attributes are deleted rather than set to None. Could I suggest updating this line of code to delete the attributes?

For context: the Nones caused test failures in another project when we attempted to switch from unittest discover to pytest as our test runner; we had a test for some complex code that was messing with various sys attributes including the sys.last_* attributes, and the test verified that those attributes were unchanged by the code under test.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: 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