Skip to content

Extract OpenFileTable from FakeFilesystem - #1380

Open
kabilanpichaipillai wants to merge 3 commits into
pytest-dev:mainfrom
kabilanpichaipillai:refactor-extract-open-file-table
Open

kabilanpichaipillai wants to merge 3 commits into
pytest-dev:mainfrom
kabilanpichaipillai:refactor-extract-open-file-table

Conversation

@kabilanpichaipillai

Copy link
Copy Markdown
Contributor

This PR extracts the open file descriptor bookkeeping from FakeFilesystem into a separate OpenFileTable class. Since FakeFilesystem is already quite large, this helps separate the file descriptor management logic into a smaller class and makes it easier to maintain.

  • Moved the open file tracking, free-fd heap and related logic into OpenFileTable.
  • Kept the existing FakeFilesystem methods as forwarders to maintain compatibility.
  • Added a read/write open_files property to preserve existing access to the file list.
  • Moved FakeFileWrapper._is_open() into OpenFileTable.is_open() and extracted the shared removal logic into OpenFileTable.remove().

Added 11 unit tests for OpenFileTable. The existing tests pass locally on Windows without any modifications, and pre-commit checks also pass.
This PR is part of the same university refactoring assignment as #1378 and #1379. I'm happy to move the class into a separate module, rename it, or make other adjustments if you prefer a different approach.

kabilanpichaipillai and others added 3 commits November 22, 2026 10:56
Move the open file descriptor list, the free descriptor heap and the
logic to add, close and look up open files into a separate class.
FakeFilesystem keeps its existing methods and the open_files attribute
as thin wrappers, so its interface does not change. Add unit tests for
the new class.
FakeFileWrapper._is_open() only inspected the open file table, so move
it there as OpenFileTable.is_open(). Also move the code removing a
wrapper from a shared descriptor, duplicated in FakeFileWrapper and
FakePipeWrapper, into OpenFileTable.remove().

This branch has not been deployed

No deployments
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