Skip to content

Restore original files when in-place edits are interrupted - #252

Open
oyeong011 wants to merge 1 commit into
jaraco:mainfrom
oyeong011:fix/in-place-interrupt-rollback
Open

Restore original files when in-place edits are interrupted#252
oyeong011 wants to merge 1 commit into
jaraco:mainfrom
oyeong011:fix/in-place-interrupt-rollback

Conversation

@oyeong011

Copy link
Copy Markdown

Interrupting Path.in_place() with Ctrl-C currently skips rollback and stream closure, but still deletes the backup in finally. 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 cover KeyboardInterrupt, SystemExit, and GeneratorExit, 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.

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.
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.

1 participant