File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11#ifndef LIBRT_THREADING_API_H
22#define LIBRT_THREADING_API_H
33
4+ #include <stdbool.h>
5+
46#include "librt_threading.h"
57
68int
@@ -17,4 +19,8 @@ extern void *LibRTThreading_API[LIBRT_THREADING_API_LEN];
1719#define LibRTThreading_Lock_locked_internal (*(char (*)(PyObject *self)) LibRTThreading_API[6])
1820#define LibRTThreading_Lock_acquire_blocking_internal (*(char (*)(PyObject *self, char blocking)) LibRTThreading_API[7])
1921
22+ static inline bool CPyLock_Check (PyObject * obj ) {
23+ return Py_TYPE (obj ) == LibRTThreading_Lock_type_internal ();
24+ }
25+
2026#endif // LIBRT_THREADING_API_H
Original file line number Diff line number Diff line change @@ -9,6 +9,10 @@ class BadBool:
99 def __bool__(self) -> bool:
1010 raise RuntimeError("bad bool")
1111
12+ class MutableLockHolder:
13+ def __init__(self) -> None:
14+ self.lock = Lock()
15+
1216def test_lock_basic() -> None:
1317 lock = Lock()
1418 assert not lock.locked()
@@ -24,6 +28,22 @@ def test_lock_context_manager() -> None:
2428 assert lock.locked()
2529 assert not lock.locked()
2630
31+ def test_mutable_lock_attribute() -> None:
32+ mutable_holder = MutableLockHolder()
33+ assert not mutable_holder.lock.locked()
34+ with mutable_holder.lock:
35+ assert mutable_holder.lock.locked()
36+ assert not mutable_holder.lock.locked()
37+
38+ dynamic_holder: Any = mutable_holder
39+ replacement = Lock()
40+ dynamic_holder.lock = replacement
41+ assert mutable_holder.lock is replacement
42+ with mutable_holder.lock:
43+ assert replacement.locked()
44+ with assertRaises(TypeError):
45+ dynamic_holder.lock = object()
46+
2747def test_lock_non_blocking() -> None:
2848 lock = Lock()
2949 assert lock.acquire()
You can’t perform that action at this time.
0 commit comments