filelock 4.2.8__tar.gz → 4.2.9__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. {filelock-4.2.8 → filelock-4.2.9}/PKG-INFO +1 -1
  2. {filelock-4.2.8 → filelock-4.2.9}/docs/changelog.rst +17 -0
  3. {filelock-4.2.8 → filelock-4.2.9}/src/filelock/_api.py +3 -1
  4. {filelock-4.2.8 → filelock-4.2.9}/src/filelock/_async_read_write.py +2 -2
  5. {filelock-4.2.8 → filelock-4.2.9}/src/filelock/_read_write.py +5 -2
  6. {filelock-4.2.8 → filelock-4.2.9}/src/filelock/_soft_rw/_async.py +4 -4
  7. {filelock-4.2.8 → filelock-4.2.9}/src/filelock/_soft_rw/_sync.py +7 -4
  8. {filelock-4.2.8 → filelock-4.2.9}/src/filelock/version.py +2 -2
  9. {filelock-4.2.8 → filelock-4.2.9}/tests/test_async_read_write.py +17 -0
  10. {filelock-4.2.8 → filelock-4.2.9}/tests/test_read_write_unit.py +31 -0
  11. {filelock-4.2.8 → filelock-4.2.9}/.gitignore +0 -0
  12. {filelock-4.2.8 → filelock-4.2.9}/LICENSE +0 -0
  13. {filelock-4.2.8 → filelock-4.2.9}/docs/_static/custom.css +0 -0
  14. {filelock-4.2.8 → filelock-4.2.9}/docs/api.rst +0 -0
  15. {filelock-4.2.8 → filelock-4.2.9}/docs/concepts.rst +0 -0
  16. {filelock-4.2.8 → filelock-4.2.9}/docs/conf.py +0 -0
  17. {filelock-4.2.8 → filelock-4.2.9}/docs/example.gif +0 -0
  18. {filelock-4.2.8 → filelock-4.2.9}/docs/how-to.rst +0 -0
  19. {filelock-4.2.8 → filelock-4.2.9}/docs/index.rst +0 -0
  20. {filelock-4.2.8 → filelock-4.2.9}/docs/license.rst +0 -0
  21. {filelock-4.2.8 → filelock-4.2.9}/docs/logo.svg +0 -0
  22. {filelock-4.2.8 → filelock-4.2.9}/docs/tutorials.rst +0 -0
  23. {filelock-4.2.8 → filelock-4.2.9}/pyproject.toml +0 -0
  24. {filelock-4.2.8 → filelock-4.2.9}/src/filelock/__init__.py +0 -0
  25. {filelock-4.2.8 → filelock-4.2.9}/src/filelock/_async.py +0 -0
  26. {filelock-4.2.8 → filelock-4.2.9}/src/filelock/_descriptor.py +0 -0
  27. {filelock-4.2.8 → filelock-4.2.9}/src/filelock/_error.py +0 -0
  28. {filelock-4.2.8 → filelock-4.2.9}/src/filelock/_identity.py +0 -0
  29. {filelock-4.2.8 → filelock-4.2.9}/src/filelock/_lease.py +0 -0
  30. {filelock-4.2.8 → filelock-4.2.9}/src/filelock/_marker.py +0 -0
  31. {filelock-4.2.8 → filelock-4.2.9}/src/filelock/_soft.py +0 -0
  32. {filelock-4.2.8 → filelock-4.2.9}/src/filelock/_soft_protocol.py +0 -0
  33. {filelock-4.2.8 → filelock-4.2.9}/src/filelock/_soft_rw/__init__.py +0 -0
  34. {filelock-4.2.8 → filelock-4.2.9}/src/filelock/_soft_rw/_protocol.py +0 -0
  35. {filelock-4.2.8 → filelock-4.2.9}/src/filelock/_soft_rw/_storage.py +0 -0
  36. {filelock-4.2.8 → filelock-4.2.9}/src/filelock/_strict.py +0 -0
  37. {filelock-4.2.8 → filelock-4.2.9}/src/filelock/_unix.py +0 -0
  38. {filelock-4.2.8 → filelock-4.2.9}/src/filelock/_util.py +0 -0
  39. {filelock-4.2.8 → filelock-4.2.9}/src/filelock/_windows.py +0 -0
  40. {filelock-4.2.8 → filelock-4.2.9}/src/filelock/asyncio.py +0 -0
  41. {filelock-4.2.8 → filelock-4.2.9}/src/filelock/py.typed +0 -0
  42. {filelock-4.2.8 → filelock-4.2.9}/tasks/benchmark.py +0 -0
  43. {filelock-4.2.8 → filelock-4.2.9}/tasks/capabilities.py +0 -0
  44. {filelock-4.2.8 → filelock-4.2.9}/tasks/capability/assert_fallback.py +0 -0
  45. {filelock-4.2.8 → filelock-4.2.9}/tasks/capability/sitecustomize.py +0 -0
  46. {filelock-4.2.8 → filelock-4.2.9}/tasks/coverage_pragmas.py +0 -0
  47. {filelock-4.2.8 → filelock-4.2.9}/tasks/deny_symlink.py +0 -0
  48. {filelock-4.2.8 → filelock-4.2.9}/tasks/termux/Dockerfile +0 -0
  49. {filelock-4.2.8 → filelock-4.2.9}/tasks/verify_filesystem.py +0 -0
  50. {filelock-4.2.8 → filelock-4.2.9}/tests/async_filelock_cancellation_helpers.py +0 -0
  51. {filelock-4.2.8 → filelock-4.2.9}/tests/capability_marks.py +0 -0
  52. {filelock-4.2.8 → filelock-4.2.9}/tests/conftest.py +0 -0
  53. {filelock-4.2.8 → filelock-4.2.9}/tests/descriptor_helpers.py +0 -0
  54. {filelock-4.2.8 → filelock-4.2.9}/tests/fork_helpers.py +0 -0
  55. {filelock-4.2.8 → filelock-4.2.9}/tests/pid_namespace_helpers.py +0 -0
  56. {filelock-4.2.8 → filelock-4.2.9}/tests/process_helpers.py +0 -0
  57. {filelock-4.2.8 → filelock-4.2.9}/tests/read_write_helpers.py +0 -0
  58. {filelock-4.2.8 → filelock-4.2.9}/tests/soft_rw/conftest.py +0 -0
  59. {filelock-4.2.8 → filelock-4.2.9}/tests/soft_rw/test_soft_rw_async.py +0 -0
  60. {filelock-4.2.8 → filelock-4.2.9}/tests/soft_rw/test_soft_rw_protocol.py +0 -0
  61. {filelock-4.2.8 → filelock-4.2.9}/tests/soft_rw/test_soft_rw_storage.py +0 -0
  62. {filelock-4.2.8 → filelock-4.2.9}/tests/soft_rw/test_soft_rw_sync.py +0 -0
  63. {filelock-4.2.8 → filelock-4.2.9}/tests/test_async_filelock.py +0 -0
  64. {filelock-4.2.8 → filelock-4.2.9}/tests/test_async_filelock_acquire_cancellation.py +0 -0
  65. {filelock-4.2.8 → filelock-4.2.9}/tests/test_async_filelock_release_cancellation.py +0 -0
  66. {filelock-4.2.8 → filelock-4.2.9}/tests/test_async_filelock_rollback_agnostic.py +0 -0
  67. {filelock-4.2.8 → filelock-4.2.9}/tests/test_async_filelock_runner_shutdown.py +0 -0
  68. {filelock-4.2.8 → filelock-4.2.9}/tests/test_async_filelock_transition_admission.py +0 -0
  69. {filelock-4.2.8 → filelock-4.2.9}/tests/test_async_read_write_cancel_wait.py +0 -0
  70. {filelock-4.2.8 → filelock-4.2.9}/tests/test_async_read_write_cancellation.py +0 -0
  71. {filelock-4.2.8 → filelock-4.2.9}/tests/test_async_read_write_worker_ownership.py +0 -0
  72. {filelock-4.2.8 → filelock-4.2.9}/tests/test_async_soft_contracts.py +0 -0
  73. {filelock-4.2.8 → filelock-4.2.9}/tests/test_async_transition_gate.py +0 -0
  74. {filelock-4.2.8 → filelock-4.2.9}/tests/test_default_mode.py +0 -0
  75. {filelock-4.2.8 → filelock-4.2.9}/tests/test_descriptor_helpers.py +0 -0
  76. {filelock-4.2.8 → filelock-4.2.9}/tests/test_error.py +0 -0
  77. {filelock-4.2.8 → filelock-4.2.9}/tests/test_filelock.py +0 -0
  78. {filelock-4.2.8 → filelock-4.2.9}/tests/test_fork_backends.py +0 -0
  79. {filelock-4.2.8 → filelock-4.2.9}/tests/test_fork_coordination.py +0 -0
  80. {filelock-4.2.8 → filelock-4.2.9}/tests/test_fork_ownership.py +0 -0
  81. {filelock-4.2.8 → filelock-4.2.9}/tests/test_fork_registries.py +0 -0
  82. {filelock-4.2.8 → filelock-4.2.9}/tests/test_host_name_grammar.py +0 -0
  83. {filelock-4.2.8 → filelock-4.2.9}/tests/test_lazy_import.py +0 -0
  84. {filelock-4.2.8 → filelock-4.2.9}/tests/test_lifetime_validation.py +0 -0
  85. {filelock-4.2.8 → filelock-4.2.9}/tests/test_lock_expiry.py +0 -0
  86. {filelock-4.2.8 → filelock-4.2.9}/tests/test_marker_records.py +0 -0
  87. {filelock-4.2.8 → filelock-4.2.9}/tests/test_process_identity.py +0 -0
  88. {filelock-4.2.8 → filelock-4.2.9}/tests/test_read_write.py +0 -0
  89. {filelock-4.2.8 → filelock-4.2.9}/tests/test_read_write_fork.py +0 -0
  90. {filelock-4.2.8 → filelock-4.2.9}/tests/test_read_write_private_link.py +0 -0
  91. {filelock-4.2.8 → filelock-4.2.9}/tests/test_soft_lease.py +0 -0
  92. {filelock-4.2.8 → filelock-4.2.9}/tests/test_soft_lifetime_warning.py +0 -0
  93. {filelock-4.2.8 → filelock-4.2.9}/tests/test_soft_stale.py +0 -0
  94. {filelock-4.2.8 → filelock-4.2.9}/tests/test_strict_soft.py +0 -0
  95. {filelock-4.2.8 → filelock-4.2.9}/tests/test_strict_soft_compat.py +0 -0
  96. {filelock-4.2.8 → filelock-4.2.9}/tests/test_strict_soft_failures.py +0 -0
  97. {filelock-4.2.8 → filelock-4.2.9}/tests/test_strict_soft_paths.py +0 -0
  98. {filelock-4.2.8 → filelock-4.2.9}/tests/test_strict_soft_races.py +0 -0
  99. {filelock-4.2.8 → filelock-4.2.9}/tests/test_strict_soft_recovery.py +0 -0
  100. {filelock-4.2.8 → filelock-4.2.9}/tests/test_strict_soft_stress.py +0 -0
  101. {filelock-4.2.8 → filelock-4.2.9}/tests/test_subclass_options.py +0 -0
  102. {filelock-4.2.8 → filelock-4.2.9}/tests/test_unix_fallback.py +0 -0
  103. {filelock-4.2.8 → filelock-4.2.9}/tests/test_util.py +0 -0
  104. {filelock-4.2.8 → filelock-4.2.9}/tests/test_virtualenv.py +0 -0
  105. {filelock-4.2.8 → filelock-4.2.9}/tox.toml +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: filelock
3
- Version: 4.2.8
3
+ Version: 4.2.9
4
4
  Import-Name: filelock
5
5
  Summary: A platform independent file lock.
6
6
  Project-URL: Changelog, https://py-filelock.readthedocs.io/en/latest/changelog.html
@@ -6,6 +6,23 @@
6
6
 
7
7
  .. towncrier release notes start
8
8
 
9
+ .. _release-4-2-9:
10
+
11
+ ********************
12
+ 4.2.9 (2026-11-04)
13
+ ********************
14
+
15
+ .. _release-4-2-9-fixed:
16
+
17
+ Fixed
18
+ =====
19
+
20
+ - :class:`~filelock.ReadWriteLock`, :class:`~filelock.SoftReadWriteLock` and their async wrappers now raise
21
+ :class:`TypeError` for a *blocking* that is not a :class:`bool`, in the constructor and on acquire, as
22
+ :class:`~filelock.FileLock` already does. Before, ``blocking=0`` waited out the full timeout on a contended
23
+ :class:`~filelock.ReadWriteLock` while ``blocking=False`` failed at once, and a truthy value such as ``"false"``
24
+ turned a single attempt into a blocking wait (:pr:`908`) by :user:`abhishekcpp007` and :user:`gaborbernat`.
25
+
9
26
  .. _release-4-2-8:
10
27
 
11
28
  ********************
@@ -1710,7 +1710,8 @@ class BaseFileLock(contextlib.ContextDecorator, metaclass=FileLockMeta): # ruff
1710
1710
 
1711
1711
 
1712
1712
  def _resolve_read_write_timeout(timeout: float, *, blocking: bool) -> float:
1713
- """Validate a read-write lock's acquire ``timeout``: ``-1`` or a non-negative number, ``inf`` meaning ``-1``."""
1713
+ # 0 would still get SQLite's full busy timeout, and a truthy "false" would turn one attempt into a blocking wait.
1714
+ _check_blocking(blocking)
1714
1715
  if (timeout := _resolve_timeout(timeout, blocking=blocking)) < 0 and timeout != -1 and blocking:
1715
1716
  msg = f"timeout must be a non-negative number or -1, not {timeout!r}"
1716
1717
  raise ValueError(msg)
@@ -2251,6 +2252,7 @@ __all__ = [
2251
2252
  "_acquire_thread_lock",
2252
2253
  "_append_exception_context",
2253
2254
  "_canonical",
2255
+ "_check_blocking",
2254
2256
  "_check_timeout_max",
2255
2257
  "_delegate_to_current",
2256
2258
  "_ensure_current_process",
@@ -189,7 +189,7 @@ class AsyncReadWriteLock:
189
189
 
190
190
  :raises RuntimeError: if the calling task already holds the write lock
191
191
  :raises Timeout: if the lock cannot be acquired within *timeout* seconds
192
- :raises TypeError: if *timeout* is a :class:`bool` or not a real number
192
+ :raises TypeError: if *timeout* is a :class:`bool` or not a real number, or *blocking* is not a :class:`bool`
193
193
  :raises ValueError: if a blocking call gets a ``nan`` *timeout* or a negative one other than ``-1``
194
194
 
195
195
  """
@@ -214,7 +214,7 @@ class AsyncReadWriteLock:
214
214
 
215
215
  :raises RuntimeError: if the calling task already holds the read lock
216
216
  :raises Timeout: if the lock cannot be acquired within *timeout* seconds
217
- :raises TypeError: if *timeout* is a :class:`bool` or not a real number
217
+ :raises TypeError: if *timeout* is a :class:`bool` or not a real number, or *blocking* is not a :class:`bool`
218
218
  :raises ValueError: if a blocking call gets a ``nan`` *timeout* or a negative one other than ``-1``
219
219
 
220
220
  """
@@ -33,6 +33,7 @@ from filelock._api import (
33
33
  AcquireReturnProxy,
34
34
  _acquire_thread_lock,
35
35
  _canonical,
36
+ _check_blocking,
36
37
  _ensure_current_process,
37
38
  _fork_transition,
38
39
  _raise_chained_errors,
@@ -394,6 +395,8 @@ class _ReadWriteLockMeta(type):
394
395
  ) -> ReadWriteLock:
395
396
  _ensure_current_process()
396
397
  _resolve_lazy_imports_before_shutdown()
398
+ # Reject a bad default at construction, as FileLock does, rather than at its first acquire.
399
+ _check_blocking(blocking)
397
400
  timeout = _seconds("timeout", timeout)
398
401
  if cls._instances_pid != _GETPID():
399
402
  cls._reset_class_after_fork()
@@ -551,7 +554,7 @@ class ReadWriteLock(metaclass=_ReadWriteLockMeta):
551
554
 
552
555
  :raises RuntimeError: if a write lock is already held on this instance
553
556
  :raises Timeout: if the lock cannot be acquired within *timeout* seconds
554
- :raises TypeError: if *timeout* is a :class:`bool` or not a real number
557
+ :raises TypeError: if *timeout* is a :class:`bool` or not a real number, or *blocking* is not a :class:`bool`
555
558
  :raises ValueError: if a blocking call gets a ``nan`` *timeout* or a negative one other than ``-1``
556
559
 
557
560
  """
@@ -579,7 +582,7 @@ class ReadWriteLock(metaclass=_ReadWriteLockMeta):
579
582
 
580
583
  :raises RuntimeError: if a read lock is already held, or a write lock is held by a different thread
581
584
  :raises Timeout: if the lock cannot be acquired within *timeout* seconds
582
- :raises TypeError: if *timeout* is a :class:`bool` or not a real number
585
+ :raises TypeError: if *timeout* is a :class:`bool` or not a real number, or *blocking* is not a :class:`bool`
583
586
  :raises ValueError: if a blocking call gets a ``nan`` *timeout* or a negative one other than ``-1``
584
587
 
585
588
  """
@@ -141,7 +141,7 @@ class AsyncSoftReadWriteLock:
141
141
 
142
142
  :raises RuntimeError: if the calling task already holds the write lock
143
143
  :raises Timeout: if the lock cannot be acquired within *timeout* seconds
144
- :raises TypeError: if *timeout* is a :class:`bool` or not a real number
144
+ :raises TypeError: if *timeout* is a :class:`bool` or not a real number, or *blocking* is not a :class:`bool`
145
145
  :raises ValueError: if a blocking call gets a ``nan`` *timeout* or a negative one other than ``-1``
146
146
 
147
147
  """
@@ -161,7 +161,7 @@ class AsyncSoftReadWriteLock:
161
161
 
162
162
  :raises RuntimeError: if the calling task already holds the read lock
163
163
  :raises Timeout: if the lock cannot be acquired within *timeout* seconds
164
- :raises TypeError: if *timeout* is a :class:`bool` or not a real number
164
+ :raises TypeError: if *timeout* is a :class:`bool` or not a real number, or *blocking* is not a :class:`bool`
165
165
  :raises ValueError: if a blocking call gets a ``nan`` *timeout* or a negative one other than ``-1``
166
166
 
167
167
  """
@@ -188,7 +188,7 @@ class AsyncSoftReadWriteLock:
188
188
  :raises RuntimeError: if the calling task already holds the write lock, if this instance was invalidated by
189
189
  :func:`os.fork`, or if :meth:`close` was called
190
190
  :raises Timeout: if the lock cannot be acquired within *timeout* seconds
191
- :raises TypeError: if *timeout* is a :class:`bool` or not a real number
191
+ :raises TypeError: if *timeout* is a :class:`bool` or not a real number, or *blocking* is not a :class:`bool`
192
192
  :raises ValueError: if a blocking call gets a ``nan`` *timeout* or a negative one other than ``-1``
193
193
 
194
194
  """
@@ -213,7 +213,7 @@ class AsyncSoftReadWriteLock:
213
213
  :raises RuntimeError: if the calling task already holds the read lock, if this instance was invalidated by
214
214
  :func:`os.fork`, or if :meth:`close` was called
215
215
  :raises Timeout: if the lock cannot be acquired within *timeout* seconds
216
- :raises TypeError: if *timeout* is a :class:`bool` or not a real number
216
+ :raises TypeError: if *timeout* is a :class:`bool` or not a real number, or *blocking* is not a :class:`bool`
217
217
  :raises ValueError: if a blocking call gets a ``nan`` *timeout* or a negative one other than ``-1``
218
218
 
219
219
  """
@@ -24,6 +24,7 @@ from filelock._api import (
24
24
  AcquireReturnProxy,
25
25
  _acquire_thread_lock,
26
26
  _canonical,
27
+ _check_blocking,
27
28
  _check_timeout_max,
28
29
  _ensure_current_process,
29
30
  _register_fork_class,
@@ -64,6 +65,8 @@ class _SoftRWMeta(type):
64
65
  on_compromise: Callable[[LeaseCompromise], None] | None = None,
65
66
  ) -> SoftReadWriteLock:
66
67
  _ensure_current_process()
68
+ # Reject a bad default at construction, as FileLock does, rather than at its first acquire.
69
+ _check_blocking(blocking)
67
70
  timeout = _seconds("timeout", timeout)
68
71
  # Passed through only when set, so a subclass that declares its own constructor without it keeps working.
69
72
  extra = {} if on_compromise is None else {"on_compromise": on_compromise}
@@ -283,7 +286,7 @@ class SoftReadWriteLock(metaclass=_SoftRWMeta):
283
286
 
284
287
  :raises RuntimeError: if a write lock is already held on this instance
285
288
  :raises Timeout: if the lock cannot be acquired within *timeout* seconds
286
- :raises TypeError: if *timeout* is a :class:`bool` or not a real number
289
+ :raises TypeError: if *timeout* is a :class:`bool` or not a real number, or *blocking* is not a :class:`bool`
287
290
  :raises ValueError: if a blocking call gets a ``nan`` *timeout* or a negative one other than ``-1``
288
291
 
289
292
  """
@@ -305,7 +308,7 @@ class SoftReadWriteLock(metaclass=_SoftRWMeta):
305
308
 
306
309
  :raises RuntimeError: if a read lock is already held, or a write lock is held by a different thread
307
310
  :raises Timeout: if the lock cannot be acquired within *timeout* seconds
308
- :raises TypeError: if *timeout* is a :class:`bool` or not a real number
311
+ :raises TypeError: if *timeout* is a :class:`bool` or not a real number, or *blocking* is not a :class:`bool`
309
312
  :raises ValueError: if a blocking call gets a ``nan`` *timeout* or a negative one other than ``-1``
310
313
 
311
314
  """
@@ -335,7 +338,7 @@ class SoftReadWriteLock(metaclass=_SoftRWMeta):
335
338
  :raises RuntimeError: if a write lock is already held on this instance, if this instance was invalidated by
336
339
  :func:`os.fork`, or if :meth:`close` was called
337
340
  :raises Timeout: if the lock cannot be acquired within *timeout* seconds
338
- :raises TypeError: if *timeout* is a :class:`bool` or not a real number
341
+ :raises TypeError: if *timeout* is a :class:`bool` or not a real number, or *blocking* is not a :class:`bool`
339
342
  :raises ValueError: if a blocking call gets a ``nan`` *timeout* or a negative one other than ``-1``
340
343
  :raises SoftFileLockProtocolError: if a snapshot cannot be read without risking overlap, or the filesystem
341
344
  refuses the no-replace hard links the protocol commits with
@@ -366,7 +369,7 @@ class SoftReadWriteLock(metaclass=_SoftRWMeta):
366
369
  :raises RuntimeError: if a read lock is already held, if a write lock is held by a different thread, if this
367
370
  instance was invalidated by :func:`os.fork`, or if :meth:`close` was called
368
371
  :raises Timeout: if the lock cannot be acquired within *timeout* seconds
369
- :raises TypeError: if *timeout* is a :class:`bool` or not a real number
372
+ :raises TypeError: if *timeout* is a :class:`bool` or not a real number, or *blocking* is not a :class:`bool`
370
373
  :raises ValueError: if a blocking call gets a ``nan`` *timeout* or a negative one other than ``-1``
371
374
  :raises SoftFileLockProtocolError: if a snapshot cannot be read without risking overlap, or the filesystem
372
375
  refuses the no-replace hard links the protocol commits with
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
18
18
  commit_id: str | None
19
19
  __commit_id__: str | None
20
20
 
21
- __version__ = version = '4.2.8'
22
- __version_tuple__ = version_tuple = (4, 2, 8)
21
+ __version__ = version = '4.2.9'
22
+ __version_tuple__ = version_tuple = (4, 2, 9)
23
23
 
24
24
  __commit_id__ = commit_id = None
@@ -566,6 +566,23 @@ async def test_async_acquire_rejects_invalid_timeout(
566
566
  await lock.close()
567
567
 
568
568
 
569
+ @pytest.mark.asyncio
570
+ @pytest.mark.parametrize("mode", [pytest.param("read", id="read"), pytest.param("write", id="write")])
571
+ @pytest.mark.parametrize("blocking", [pytest.param("false", id="str"), pytest.param(0, id="int")])
572
+ async def test_async_acquire_rejects_a_blocking_that_is_not_a_bool(
573
+ lock_file: str, mode: Literal["read", "write"], blocking: str | int
574
+ ) -> None:
575
+ lock: Final = AsyncReadWriteLock(lock_file, is_singleton=False)
576
+ acquire: Final = lock.acquire_read if mode == "read" else lock.acquire_write
577
+ try:
578
+ with pytest.raises(TypeError, match="blocking must be a bool"):
579
+ await asyncio.create_task(
580
+ acquire(blocking=blocking) # ty: ignore[invalid-argument-type] # the rejected type is the contract
581
+ )
582
+ finally:
583
+ await lock.close()
584
+
585
+
569
586
  @pytest.mark.asyncio
570
587
  @pytest.mark.parametrize("mode", [pytest.param("read", id="read"), pytest.param("write", id="write")])
571
588
  @pytest.mark.parametrize(
@@ -125,6 +125,18 @@ def test_constructor_rejects_a_timeout_that_is_not_a_number(
125
125
  )
126
126
 
127
127
 
128
+ @pytest.mark.parametrize("blocking", [pytest.param("false", id="str"), pytest.param(0, id="int")])
129
+ def test_constructor_rejects_a_blocking_that_is_not_a_bool(
130
+ lock_type: type[ReadWriteLock | SoftReadWriteLock], blocking: str | int, lock_file: str
131
+ ) -> None:
132
+ with pytest.raises(TypeError, match="blocking must be a bool"):
133
+ lock_type(
134
+ lock_file,
135
+ blocking=blocking, # ty: ignore[invalid-argument-type] # the rejected type is the contract
136
+ is_singleton=False,
137
+ )
138
+
139
+
128
140
  def test_singleton_rejects_different_blocking(lock_file: str) -> None:
129
141
  lock = ReadWriteLock(lock_file, blocking=True)
130
142
  with pytest.raises(ValueError, match="Singleton lock created with"):
@@ -967,6 +979,25 @@ def sync_locks(tmp_path: Path) -> Generator[tuple[ReadWriteLock, ReadWriteLock]]
967
979
  yield holder, contender
968
980
 
969
981
 
982
+ @pytest.mark.parametrize("mode", [pytest.param("read", id="read"), pytest.param("write", id="write")])
983
+ @pytest.mark.parametrize("blocking", [pytest.param("false", id="str"), pytest.param(0, id="int")])
984
+ def test_acquire_rejects_a_blocking_that_is_not_a_bool(
985
+ timeout_locks: tuple[ReadWriteLock | SoftReadWriteLock, ReadWriteLock | SoftReadWriteLock],
986
+ mode: Literal["read", "write"],
987
+ blocking: str | int,
988
+ ) -> None:
989
+ # Contended, so a 0 read as blocking would wait out the contender's timeout instead of failing fast.
990
+ holder, contender = timeout_locks
991
+ acquire: Final = contender.acquire_read if mode == "read" else contender.acquire_write
992
+ with holder.acquire_write(blocking=False):
993
+ started: Final = time.monotonic()
994
+ with pytest.raises(TypeError, match="blocking must be a bool"):
995
+ acquire(blocking=blocking) # ty: ignore[invalid-argument-type] # the rejected type is the contract
996
+ assert time.monotonic() - started < 5
997
+ with contender.acquire_write(blocking=False):
998
+ pass
999
+
1000
+
970
1001
  @pytest.mark.parametrize("mode", [pytest.param("read", id="read"), pytest.param("write", id="write")])
971
1002
  @INVALID_TIMEOUTS
972
1003
  @pytest.mark.parametrize("reentrant", [pytest.param(True, id="reentrant"), pytest.param(False, id="first")])
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes