From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Thu, 22 May 2025 17:12:21 +0000 (+0200) Subject: [3.14] gh-134322: Fix `repr(threading.RLock)` (GH-134389) (#134528) X-Git-Tag: v3.14.0b2~46 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=068d570be84eab2ef271204e7ba9dd37391791d4;p=thirdparty%2FPython%2Fcpython.git [3.14] gh-134322: Fix `repr(threading.RLock)` (GH-134389) (#134528) gh-134322: Fix `repr(threading.RLock)` (GH-134389) Fix the `__repr__` value of `threading.RLock` from `_thread` module, when just created. (cherry picked from commit fade146cfb1616ad7b3b918bedb86756dedf79e6) Co-authored-by: Duprat --- diff --git a/Lib/test/lock_tests.py b/Lib/test/lock_tests.py index 0e8c75ff5c49..fb11f4828957 100644 --- a/Lib/test/lock_tests.py +++ b/Lib/test/lock_tests.py @@ -332,6 +332,26 @@ class RLockTests(BaseLockTests): """ Tests for recursive locks. """ + def test_repr_count(self): + # see gh-134322: check that count values are correct: + # when a rlock is just created, + # in a second thread when rlock is acquired in the main thread. + lock = self.locktype() + self.assertIn("count=0", repr(lock)) + self.assertIn("lock.thread; int locked = rlock_locked_impl(self); - size_t count = self->lock.level + 1; + size_t count; + if (locked) { + count = self->lock.level + 1; + } + else { + count = 0; + } return PyUnicode_FromFormat( "<%s %s object owner=%" PY_FORMAT_THREAD_IDENT_T " count=%zu at %p>", locked ? "locked" : "unlocked",