Repository navigation
fix(foundation): back the abandoned-extraction close with weakref.finalize (#1997) - #1998
Merged
Merged
Conversation
…alize (#1997) GraalPy never calls `__del__`, so an `auto=False` extraction dropped before EOF kept the file it opened. `Extractor.__init__` now registers a `weakref.finalize` over the input stream alone, and only for a stream it owns, so a caller's stream is never closed by it. `_cleanup` and `__exit__` detach it, and `__del__` stays, sharing the same guarded close. New tests check the finaliser on CPython too: it is registered over the stream rather than the extractor, closes an owned handle with `__del__` patched out, is detached on a finished extraction, and spares a caller's stream, plain or wrapped.
Owner
Author
|
GOOD TO GO at
One behaviour change, noted here: |
Contributor
|
Coverage: 91.52% (unit tier, Python 3.15,
Per-file detail: the |
5 tasks done
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.
make pylint,make mypy,make isort)make testpasses, and a test case covers the changeWhat is the purpose of your pull request?
fix— corrects a defectDescription of your pull request and other information
On GraalPy, an extraction abandoned before EOF never closed the file it had opened, because GraalPy never calls
Extractor.__del__.The fix.
Extractor.__init__now also registers aweakref.finalize, stored as_finalizer. It works as follows:_owns_input()holds, so a stream the caller passed in is never closed._cleanupand__exit__detach it, so a finished extraction is not closed twice.__del__stays, because tests and subclasses call it directly. Both backstops share_release_input.Tests. The new
FinaliserBackstopWithoutDeltests intest_extraction_ownership.pyfail without the fix on CPython (6 failed) and on GraalPy 25.4.4 (8 failed). They pass on both with it. The othertests/foundationextraction files pass on both interpreters.Found separately:
__exit__closes a caller-supplied stream too, which this PR leaves as it is (#1999).Closes #1997