Skip to content

Conversation

@bluetech
Copy link
Member

The old-style sys.exc_info() triplet is redundant nowadays with (type(exc), exc, exc.__traceback__), and is beginning to get soft-deprecated in Python 3.12.

Add a nicer API to ExceptionInfo which takes just the exc instead of the triplet. There are already a few internal uses which benefit.

"""Return an ExceptionInfo for an existing exc_info tuple.
"""Return an ExceptionInfo for an existing exception.
The exception must have a non-``None`` ``__traceback__`` attribute,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only hitch here is this subtlety. An alternative is to just allow ExcInfo to have a missing traceback...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I personally prefer to get a clear error at this point, rather than make ExceptionInfo.__traceback__ be Optional.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, agreed.

@bluetech bluetech force-pushed the exceptioninfo-from-exception branch from 9fd7d5b to dc5dd8c Compare April 12, 2023 09:57
The old-style `sys.exc_info()` triplet is redundant nowadays with
`(type(exc), exc, exc.__traceback__)`, and is beginning to get
soft-deprecated in Python 3.12.

Add a nicer API to ExceptionInfo which takes just the exc instead of the
triplet. There are already a few internal uses which benefit.
@bluetech bluetech force-pushed the exceptioninfo-from-exception branch from dc5dd8c to 424c3ee Compare April 12, 2023 10:16
Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

"""Return an ExceptionInfo for an existing exc_info tuple.
"""Return an ExceptionInfo for an existing exception.
The exception must have a non-``None`` ``__traceback__`` attribute,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I personally prefer to get a clear error at this point, rather than make ExceptionInfo.__traceback__ be Optional.

@bluetech bluetech merged commit 5d13853 into pytest-dev:main Apr 13, 2023
@bluetech bluetech deleted the exceptioninfo-from-exception branch April 13, 2023 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants