Restore original files when in-place edits are interrupted - #252
Open
oyeong011 wants to merge 1 commit into
Open
Restore original files when in-place edits are interrupted#252oyeong011 wants to merge 1 commit into
oyeong011 wants to merge 1 commit into
Conversation
Constraint: Preserve rollback behavior for all exceptions leaving the context. Confidence: high Scope-risk: narrow Tested: Full pytest suite and a real SIGINT during an in-place rewrite. Not-tested: Windows runtime; existing lint findings remain unchanged.
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.
Interrupting
Path.in_place()with Ctrl-C currently skips rollback and stream closure, but still deletes the backup infinally. The original file can therefore be lost even though the documented context contract promises restoration on exceptions.Apply the existing rollback handler to
BaseException, then re-raise as before. Regression cases coverKeyboardInterrupt,SystemExit, andGeneratorExit, verifying original content, closed streams, and backup cleanup.Validation: all three regression cases failed before the fix. The full pytest suite passes (145 passed, 1 existing skip). A real SIGINT after flushing partial replacement content restored the original file; a subsequent successful rewrite also worked. Ruff formatting passes, and comparison with base shows no new lint findings in the changed files. Tested on macOS/Python 3.14.6; Windows and the remaining version matrix were not run.
AI disclosure: This patch, regression tests, and description were prepared with OpenAI Codex assistance. The reported checks were executed locally.