♻️ refactor(util): test helpers via public locks - #764
Merged
Merged
Conversation
tests/test_util.py called three private helpers from filelock._util and patched filelock._util.os.lstat. Drive the same races through SoftFileLock, and patch the stdlib Path.rename and os.lstat to play a peer. Every break_lock_file caller suppresses OSError, so drop the guard around the re-check lstat. touch has one caller. It passes a descriptor each time, so make fd required and drop the path-based symlink test, which reached a branch no caller takes where utime accepts a descriptor. Open the break_lock_file docstring with why it renames first. Claude-Session: https://claude.ai/code/session_0185Ga4wvPxDBm7NwTthKqYf
gaborbernat
force-pushed
the
simp-util-docs
branch
from
October 1, 2026 23:36
d11c0af to
adff286
Compare
gaborbernat
enabled auto-merge (squash)
October 1, 2026 23:38
gaborbernat
disabled auto-merge
October 2, 2026 00:16
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.
This follows up #762 with edits that missed its merge, and moves
tests/test_util.pyoff the privatefilelock._utilmodule. 🧹 Those tests called three private helpers and patchedfilelock._util.os.lstat, so a refactor inside the module could break them while every lock kept its behavior.Each race starts from a dead holder's marker and runs through
SoftFileLock. We patchPath.renameoros.lstatto play a peer that recreates or releases the marker mid-break, since those are the filesystem calls the break makes. Two guards in_util.pychanged nothing a caller could observe. Everybreak_lock_filecaller suppressesOSError, so thetryaround its re-checklstatgoes;touchhas one caller, which passes a descriptor each time, sofdbecomes required.No lock changes behavior. The
break_lock_filedocstring opens with the reason it renames before unlinking. Of several processes racing to break the same lock, the first to rename takes the file and the rest getOSError.