Skip to content

πŸ› fix(api): reject a non-bool blocking in acquire() - #870

Merged
gaborbernat merged 2 commits into
tox-dev:mainfrom
simpleqt:fix-acquire-blocking-type
Oct 28, 2026
Merged

gaborbernat merged 2 commits into
tox-dev:mainfrom
simpleqt:fix-acquire-blocking-type

Conversation

@simpleqt

@simpleqt simpleqt commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

A lock built with a configuration value such as blocking="false" failed fast, because the constructor and the blocking setter reject anything that is not a bool. acquire(blocking=...) took the same string and read it as truthy, so a call meant as a single attempt waited for the instance's timeout, without a limit at the default -1. The process hung where it should have raised.

acquire() on FileLock, SoftFileLock and their async twins now runs the validator the constructor and setter already share, after None has resolved to the instance's setting, so every entry point that takes blocking raises the same TypeError for a non-bool. πŸ”’ A call that passed blocking=1 or blocking=0 and relied on truthiness now raises; pass True or False.

… it as truthy

The constructor and the ``blocking`` setter reject a value that is not a bool, but
``acquire()`` accepted one and fell back to truthiness. A configuration string such as
``"false"`` is truthy, so a call that asked for a single non-blocking attempt waited for the
instance's ``timeout`` instead, and with the default ``timeout=-1`` that wait has no limit.
``acquire()`` now validates the argument the same way the constructor does, in both the sync
and the async implementation, and raises the same ``TypeError``.

Signed-off-by: simpleqt <2015900818@qq.com>
Copilot AI balanced review requested due to automatic review settings October 20, 2026 14:38

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

The constructor and the setter already share the validator, so the
acquire() call sites need no comment restating that; one line on the
sync path keeps the why. The tests that passed blocking=None are gone:
test_singleton_handed_out_while_finalizing_keeps_its_hold and the async
singleton test already drive acquire() through an instance built with
blocking=False and expect Timeout, and an uncontended acquire passes
whatever blocking resolves to. One string and one int per suite cover
the rejected types.
@gaborbernat gaborbernat changed the title fix(api): reject a non-bool blocking in acquire() instead of treating it as truthy πŸ› fix(api): reject a non-bool blocking in acquire() Oct 28, 2026
@gaborbernat gaborbernat reopened this Oct 28, 2026
@gaborbernat
gaborbernat merged commit 1f87ca8 into tox-dev:main Oct 28, 2026
71 of 100 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants