Repository navigation
Conversation
Keep pathlib's posixpath identity marker unchanged while other module imports remain faked. Add lifecycle, cache-order and fake-I/O regressions for pytest-dev#1359.
This branch has not been deployed
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.
Describe the changes
Addresses #1359.
Keep the original
posixpathreference inpathlibandpathlib._local. Python 3.13+ uses that reference as an identity marker when computing a real path's normalized case. Replacing it makes a real POSIX path cache a lowercase value even though its parser remains the original module.This fixes the cache contamination in both orders: a real path first used inside a fake filesystem, and a path cached before patching whose children are created during patching. It preserves equality, hashes, dictionary lookup, parents and
relative_tobetween real paths across pause/resume, teardown and subsequent sessions.The guard is restricted to these two stdlib modules. Other modules'
posixpathimports remain patched, and existing real paths still use the fake filesystem for operations such asiterdir(). It does not rewrite original parser classes, clear arbitrary object caches or change fake/real class equality.Scope limitation
The report's exact reverse-order example also compares the real path returned by
relative_towith a newly created fakePath("src"). That final mixed real/fake equality remains false because their parser identities differ. An independent lowercase-only probe reproduces this on both unchanged main and this patch, on Python 3.12 and 3.13, without cache contamination.The two exact reported pytest examples therefore improve from 2 passed / 2 failed to 3 passed / 1 failed on Python 3.13: the original
relative_toexception is resolved, but the mixed-type comparison remains. Comparing withtype(ROOT)("src")instead makes all four tests pass. This PR deliberately does not claim to resolve that separate equality behavior or automatically close the issue.Validation
Against main
45d460c7b93ffd0ddfb29e37b5f7e0930f7c91e4, on Linux:posixpathpatch/restoration.relative_toValueError; the two compatibility tests pass.python -bb -m pyfakefs.tests.all_tests: Python 3.12 runs 2,503 tests, OK (1,045 skipped, 2 expected failures); Python 3.13 runs 2,499 tests, OK (1,039 skipped, 2 expected failures).Tasks
AI assistance: this patch and its tests were developed with OpenAI Codex. A separate Codex review independently executed the regression and compatibility probes described above.