📝 docs: say acquire() falls back to the lock's blocking attribute - #733
Open
hxperl wants to merge 2 commits into
Open
📝 docs: say acquire() falls back to the lock's blocking attribute#733hxperl wants to merge 2 commits into
hxperl wants to merge 2 commits into
Conversation
The `blocking` parameter of `BaseFileLock.acquire` and
`BaseAsyncFileLock.acquire` was documented as "defaults to True", but the
signature default is `None` and `None` resolves to `self._context.blocking`,
not to `True`. That attribute is settable both at construction
(`FileLock(path, blocking=False)`) and at runtime (`lock.blocking = False`),
so for any lock configured as non-blocking the documented default is wrong.
The two sibling parameters in the same docstring already describe this
correctly ("``None`` means use the default :attr:`~timeout`" /
":attr:`~poll_interval`"); `blocking` was the only one of the three that
described a literal default instead of the fallback. Reworded to match.
No behaviour change.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NbQSLKhdfSRcBeGWhaaV6T
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NbQSLKhdfSRcBeGWhaaV6T
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.
The
blockingparameter ofBaseFileLock.acquireandBaseAsyncFileLock.acquireis documented as "defaults to True". The signature default isNone, andNonedoes not meanTrue— it means "use the lock's ownblockingattribute":(
_api.py:1032,asyncio.py:295)That attribute is configurable at construction (
FileLock(path, blocking=False)) and settable at runtime (lock.blocking = False, the setter added in 3.14.0). So for any lock that was configured as non-blocking,acquire()with no arguments is non-blocking — the opposite of what the docstring promises.The two sibling parameters in the very same docstring already describe this correctly:
blockingwas the only one of the three that stated a literal default instead of the fallback.Reproduction
Against
main@4efd93e, before changing anything:The control case blocks for its full timeout, which is what isolates the difference to the inherited
blockingvalue rather than to anything about the timeout path.The change
One docstring sentence in each of
_api.pyandasyncio.py, reworded to the "Nonemeans use the default :attr:..." form the neighbouring parameters already use. No behaviour change, no signature change.What I verified
pytest tests/test_filelock.py tests/test_async_filelock.py tests/test_subclass_options.py -p no:randomly --no-cov: 405 passed, 32 skipped — identical to the same command on the unmodified commit (I ran the baseline first, 31.28s vs 32.70s).ruff format --check→2 files already formatted;ruff check→All checks passed!.nitpicky = True:build succeeded.The new:attr:renders as a resolved link to#filelock.BaseFileLock.blockingin both the sync and async entries, which is the only real risk in a change like this.What I did not verify
macOS arm64, Python 3.14 only; CI will need to confirm other platforms. I did not run the full suite — it is dominated by real-time sleeps and was heading for well over an hour on this machine, so I ran the three files covering
acquire/blockingsemantics instead. Given the change is a docstring with no code path attached, I judged that proportionate, but say so plainly rather than implying a full green run.A judgement call, and one thing deliberately left out
I used
:attr:~blockingin `_api.py` and `:attr:`~BaseFileLock.blockinginasyncio.py, matching how each file already spells itstimeout/poll_intervalreferences rather than making the two identical. Happy to unify them if you would rather.Separately, while checking the rendered output I noticed
ReadWriteLock'sblockingparameter is documented as "when True (default), retry the nonblocking attempt every poll_interval seconds...". That is a different function with a different default and I have not verified it, so it is not part of this PR — flagging it only in case it is worth a look.