chore: update framework tests to pass under Python 3.12 #1081
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The behaviour of descriptors changed in 3.12, so that when
__set_name__
raises an exception, that exception reaches the code that did the name setting, with a note attached, unlike earlier Python where the exception was chained.Minimal code
Python 3.11
Python 3.12
In the framework tests, we verify that the event source is not being reused by checking the
str
of the causing exception, but that doesn't work in both 3.12 and earlier Python because of this Python change.I couldn't find a way to use exactly the same code in Python 3.12 and earlier, so have checked for the presence of the
__notes__
attribute - if it is there, then the "Error calling set_name" piece will be in in the notes, and so we look at the exception itself; if it is not there, then we assume the earlier behaviour and look at the causing exception. This could be a check againstsys.version_info
instead if that was preferred.