Fix pathlib Path wrapping to use concrete platform path type#193
Merged
seanwevans merged 1 commit intomainfrom Apr 21, 2026
Merged
Conversation
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.
Motivation
pathlib.Pathsubclass previously inherited frommodule.Path, which can be an abstract class and may not match the concrete platform-specificPathimplementation, causing platform-specific behavior regressions.Pathsemantics across platforms while retaining sandbox enforcement for file operations.Description
SandboxedPathfrom the concrete runtime path class usingtype(module.Path())instead ofmodule.Pathto preserve platform-specific behavior.open()override onSandboxedPath, which continues to applyio.text_encoding()for text modes and delegates to_blocked_open(...)with the same argument flow.mod.Pathwith the newSandboxedPathin thepathlibbranch of_wrap_module()inpyisolate/runtime/thread.py.test_pathlib_path_read_text_respects_fs_policyintests/test_policy_enforcement.pythat importspathlibinside the sandbox and assertsPath(...).read_text()under allowed and blocked filesystem policies.Testing
pytest -q tests/test_policy_enforcement.py::test_pathlib_path_read_text_respects_fs_policy tests/test_policy_enforcement.py::test_policy_import_and_fs tests/test_thread_imports.pyand all tests passed (5 passed).Pathtype and the test is written to be OS-portable for CI runners.Codex Task