Skip to content

Readability refactoring in FakeFileOpen and Patcher - #1378

Merged
mrbean-bremen merged 4 commits into
pytest-dev:mainfrom
kabilanpichaipillai:refactor-open-and-patcher-readability
Nov 22, 2026
Merged

mrbean-bremen merged 4 commits into
pytest-dev:mainfrom
kabilanpichaipillai:refactor-open-and-patcher-readability

Conversation

@kabilanpichaipillai

Copy link
Copy Markdown
Contributor

This PR includes a few small refactoring changes to improve readability and maintainability without changing the existing behaviour.

Changes:

  • Moved the pipe re-opening logic in FakeFileOpen.call into _open_pipe_wrapper().
  • Extracted the nested permission condition in FakeFileOpen._init_file_object into _is_access_denied().
  • Named the nine-part condition in Patcher.init as has_custom_arguments.
  • Renamed Patcher._isStale to _is_stale to follow PEP 8 naming conventions.

These changes make some of the longer methods and complex conditions easier to understand and maintain. I ran the existing tests locally on Windows, and they passed without any modifications. Pre-commit checks also pass.

This PR is part of a university refactoring assignment. I am happy to make adjustments or remove any changes based on your feedback.

Move the branch that wraps an already open fake pipe descriptor
unchanged into _open_pipe_wrapper(), shortening call().
Move the nested read/write permission condition into the new
_is_access_denied() helper so the caller reads as a single check.
Name the nine-part condition in Patcher.__init__ as
has_custom_arguments so its intent is clear at the call site.
Use snake_case like the surrounding Patcher attributes (PEP 8).

@mrbean-bremen mrbean-bremen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's ok! It doesn't change any functionality and does indeed increase readability a bit. I use to do this kind of refactoring myself, usually in the context of some other change.
Do you wanted to add more changes?

@kabilanpichaipillai

Copy link
Copy Markdown
Contributor Author

That's ok! It doesn't change any functionality and does indeed increase readability a bit. I use to do this kind of refactoring myself, usually in the context of some other change. Do you wanted to add more changes?

Thank you for the quick review! No further changes are planned for this PR, so it's ready to merge as is. I’m planning to submit couple more separate PRs for code refactoring.

@mrbean-bremen
mrbean-bremen merged commit 482d034 into pytest-dev:main Nov 22, 2026
104 checks passed
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.

2 participants