Repository navigation
Fix os.path.sameopenfile for fake file descriptors - #1349
Open
anshurajbisoyi98-ctrl wants to merge 3 commits into
Open
anshurajbisoyi98-ctrl wants to merge 3 commits into
anshurajbisoyi98-ctrl wants to merge 3 commits into
Conversation
Signed-off-by: ANSHU-RAJ-BISOYI <230949664+anshurajbisoyi98-ctrl@users.noreply.github.com>
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
Fixes #1346.
os.path.sameopenfile()currently calls the real filesystem'sfstat()with fake file descriptors. Comparing two handles to the same fake file therefore raisesEBADF, or compares unrelated real descriptors when those numbers happen to exist.Register
sameopenfilefor patching and compare fakefstat()results through the existingsamestat()helper. Invalid descriptors continue to raiseOSError. The regression checks matching and different files, a descriptor compared with itself, and closed descriptors under Linux, macOS, and Windows simulation.Testing
Codex ran these checks locally on macOS arm64 with Python 3.13.12:
python -m pyfakefs.tests.all_tests: 2,413 tests run; OK with 973 skips and 2 expected failures, with the extra dependency group installed.pytest pyfakefs/pytest_tests -q: 34 passed, 1 skipped, 2 xpassed.pre-commit run --all-files: all hooks passed, including Ruff and mypy; hooks used the configured Python 3.10 runtime.git diff --check: clean.With
TEST_REAL_FS=1, the suite has one failure inRealOsModuleTest.test_lexists_with_trailing_separator_macos. The identical failure occurs in a clean checkout of upstream commit796c48e; it concerns real macOS symlink behavior and is outside this change. Native Windows/Linux, root-user runs, the full Python-version CI matrix, and CI's Linux pytype job were not run locally.Tasks
AI usage
I used Codex for investigation, implementation, tests. Codex performed the verification listed above.
I kept the fix in the existing path adapter, using fake filesystem metadata to compare open descriptors. The regression tests cover matching files, different files, and closed descriptors across all three simulated operating systems.
AI assistance
I used OpenAI Codex to help investigate, implement, and check parts of this change. I take responsibility for the submitted changes.