Skip to content

Commit 343add6

Browse files
committed
gh-89554: Document _thread.LockType as a class
_thread.LockType is a class (the type of lock objects), but was documented with the ".. data::" directive, so ":class:" cross-references to it cannot resolve against a py:class target. Switch the entry to ".. class::", move it next to the lock methods, and document acquire(), release() and locked() as methods of the class. The methods move from the _thread.lock.* anchors to _thread.LockType.*, so the old IDs are recorded in Doc/tools/removed-ids.txt.
1 parent 2f8f569 commit 343add6

2 files changed

Lines changed: 40 additions & 39 deletions

File tree

Doc/library/_thread.rst

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ This module defines the following constants and functions:
3636
This is now a synonym of the built-in :exc:`RuntimeError`.
3737

3838

39-
.. data:: LockType
40-
41-
This is the type of lock objects.
42-
43-
4439
.. function:: start_new_thread(function, args[, kwargs])
4540

4641
Start a new thread and return its identifier. The thread executes the
@@ -162,58 +157,59 @@ This module defines the following constants and functions:
162157
.. versionadded:: 3.2
163158

164159

165-
Lock objects have the following methods:
166-
160+
.. class:: LockType
167161

168-
.. method:: lock.acquire(blocking=True, timeout=-1)
162+
This is the type of lock objects.
169163

170-
Without any optional argument, this method acquires the lock unconditionally, if
171-
necessary waiting until it is released by another thread (only one thread at a
172-
time can acquire a lock --- that's their reason for existence).
164+
Lock objects have the following methods:
173165

174-
If the *blocking* argument is present, the action depends on its
175-
value: if it is false, the lock is only acquired if it can be acquired
176-
immediately without waiting, while if it is true, the lock is acquired
177-
unconditionally as above.
166+
.. method:: acquire(blocking=True, timeout=-1)
178167

179-
If the floating-point *timeout* argument is present and positive, it
180-
specifies the maximum wait time in seconds before returning. A negative
181-
*timeout* argument specifies an unbounded wait. You cannot specify
182-
a *timeout* if *blocking* is false.
168+
Without any optional argument, this method acquires the lock unconditionally, if
169+
necessary waiting until it is released by another thread (only one thread at a
170+
time can acquire a lock --- that's their reason for existence).
183171

184-
The return value is ``True`` if the lock is acquired successfully,
185-
``False`` if not.
172+
If the *blocking* argument is present, the action depends on its
173+
value: if it is false, the lock is only acquired if it can be acquired
174+
immediately without waiting, while if it is true, the lock is acquired
175+
unconditionally as above.
186176

187-
.. versionchanged:: 3.2
188-
The *timeout* parameter is new.
177+
If the floating-point *timeout* argument is present and positive, it
178+
specifies the maximum wait time in seconds before returning. A negative
179+
*timeout* argument specifies an unbounded wait. You cannot specify
180+
a *timeout* if *blocking* is false.
189181

190-
.. versionchanged:: 3.2
191-
Lock acquires can now be interrupted by signals on POSIX.
182+
The return value is ``True`` if the lock is acquired successfully,
183+
``False`` if not.
192184

193-
.. versionchanged:: 3.14
194-
Lock acquires can now be interrupted by signals on Windows.
185+
.. versionchanged:: 3.2
186+
The *timeout* parameter is new.
195187

188+
.. versionchanged:: 3.2
189+
Lock acquires can now be interrupted by signals on POSIX.
196190

197-
.. method:: lock.release()
191+
.. versionchanged:: 3.14
192+
Lock acquires can now be interrupted by signals on Windows.
198193

199-
Releases the lock. The lock must have been acquired earlier, but not
200-
necessarily by the same thread.
194+
.. method:: release()
201195

196+
Releases the lock. The lock must have been acquired earlier, but not
197+
necessarily by the same thread.
202198

203-
.. method:: lock.locked()
199+
.. method:: locked()
204200

205-
Return the status of the lock: ``True`` if it has been acquired by some thread,
206-
``False`` if not.
201+
Return the status of the lock: ``True`` if it has been acquired by some thread,
202+
``False`` if not.
207203

208-
In addition to these methods, lock objects can also be used via the
209-
:keyword:`with` statement, e.g.::
204+
In addition to these methods, lock objects can also be used via the
205+
:keyword:`with` statement, e.g.::
210206

211-
import _thread
207+
import _thread
212208

213-
a_lock = _thread.allocate_lock()
209+
a_lock = _thread.allocate_lock()
214210

215-
with a_lock:
216-
print("a_lock is locked while this executes")
211+
with a_lock:
212+
print("a_lock is locked while this executes")
217213

218214
**Caveats:**
219215

Doc/tools/removed-ids.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ library/symtable.html: symtable.Class.get_methods
1414
library/sys.html: sys._enablelegacywindowsfsencoding
1515
c-api/import.html: c.PyImport_LazyImportsMode.PyImport_LAZY_NONE
1616

17+
# gh-89554: _thread lock methods are now documented under the LockType class
18+
library/_thread.html: thread.lock.acquire
19+
library/_thread.html: thread.lock.release
20+
library/_thread.html: thread.lock.locked
21+
1722
## Old names for grammar tokens
1823
reference/expressions.html: grammar-token-python-grammar-comp_for
1924
reference/expressions.html: grammar-token-python-grammar-comp_if

0 commit comments

Comments
 (0)