Skip to content

Commit 6487bef

Browse files
committed
Apply last suggestions
1 parent 57b0402 commit 6487bef

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

Lib/test/lock_tests.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ class RLockTests(BaseLockTests):
340340
def test_repr_count(self):
341341
# see gh-134322: check that count values are correct:
342342
# when a rlock is just created,
343-
# in a secondary thread when rlock is acquired in the main thread.
343+
# in a second thread when rlock is acquired in the main thread.
344344
lock = self.locktype()
345345
self.assertIn("count=0", repr(lock))
346346
self.assertIn("<unlocked", repr(lock))
@@ -349,13 +349,13 @@ def test_repr_count(self):
349349
self.assertIn("count=2", repr(lock))
350350
self.assertIn("<locked", repr(lock))
351351

352-
l = []
353-
def acquire():
354-
l.append(repr(lock))
355-
with Bunch(acquire, 1):
352+
result = []
353+
def call_repr():
354+
result.append(repr(lock))
355+
with Bunch(call_repr, 1):
356356
pass
357-
self.assertIn("count=2", l[0])
358-
self.assertIn("<locked", l[0])
357+
self.assertIn("count=2", result[0])
358+
self.assertIn("<locked", result[0])
359359

360360
def test_reacquire(self):
361361
lock = self.locktype()

Modules/_threadmodule.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,15 +1022,12 @@ rlock_traverse(PyObject *self, visitproc visit, void *arg)
10221022
return 0;
10231023
}
10241024

1025-
/*
1026-
helper function used by rlock_locked and rlock_repr.
1027-
*/
10281025
static int
1029-
rlock_locked_impl(rlockobject *self) {
1026+
rlock_locked_impl(rlockobject *self)
1027+
{
10301028
return PyMutex_IsLocked(&self->lock.mutex);
10311029
}
10321030

1033-
10341031
static void
10351032
rlock_dealloc(PyObject *self)
10361033
{
@@ -1227,16 +1224,17 @@ rlock_repr(PyObject *op)
12271224
{
12281225
rlockobject *self = rlockobject_CAST(op);
12291226
PyThread_ident_t owner = self->lock.thread;
1227+
int locked = rlock_locked_impl(self);
12301228
size_t count;
1231-
if (rlock_locked_impl(self)) {
1229+
if (locked) {
12321230
count = self->lock.level + 1;
12331231
}
12341232
else {
12351233
count = 0;
12361234
}
12371235
return PyUnicode_FromFormat(
12381236
"<%s %s object owner=%" PY_FORMAT_THREAD_IDENT_T " count=%zu at %p>",
1239-
owner ? "locked" : "unlocked",
1237+
locked ? "locked" : "unlocked",
12401238
Py_TYPE(self)->tp_name, owner,
12411239
count, self);
12421240
}

0 commit comments

Comments
 (0)