Repository navigation
Conversation
WITH_CLEANUP only silenced the exception when __exit__ returned the True singleton, so a true non-bool result such as 1 let the exception propagate. Test the result with ObjectIsTrue, as CPython 3.4 does with PyObject_IsTrue, and return any error raised while doing so.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
WITH_CLEANUPonly silenced the exception when__exit__returned theTruesingleton, so a context manager whose__exit__returns e.g.1let the exception through.CPython 3.4 tests the result with
PyObject_IsTrueand jumps to the error path if that raises. This usespy.ObjectIsTrue, which followsPyObject_IsTrue(including__bool__/__len__on class instances since #222), and returns its error.Tests: vm/tests/with.py now checks that true non-bool results (
1,"potato",[0],0.5,object()) silence the error, false ones (None,False,0,"",[],0.0, and instances with a false__bool__or zero__len__) don't, and that an exception raised by the result's__bool__propagates. The new cases fail on main and pass here; the file also passes under CPython.go test -race ./...passes on Go 1.18, 1.19 and 1.27.Fixes #267.