From dd0c19862b0e0f500a322894645c008047d10df1 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 24 May 2026 01:31:06 +0530 Subject: [PATCH 1/2] gh-132578: Add regression test ensuring Thread subclasses can safely define _handle --- Lib/test/test_threading.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py index 3d01804513bde98..ba8084630f38490 100644 --- a/Lib/test/test_threading.py +++ b/Lib/test/test_threading.py @@ -2847,5 +2847,25 @@ def run_last(): err.decode()) +class ThreadHandleRegressionTest(unittest.TestCase): + def test_subclass_can_define_handle(self): + # gh-132578: Ensure third-party libraries overriding or defining + # a custom `_handle` attribute/method don't clash with CPython internal implementation details. + class CustomThread(threading.Thread): + def __init__(self): + super().__init__() + self._handle = "custom_third_party_handle_value" + + def run(self): + pass + + t = CustomThread() + t.start() + t.join() + + # Assert that our custom handle parameter was preserved and did not break the thread run lifecycle + self.assertEqual(t._handle, "custom_third_party_handle_value") + + if __name__ == "__main__": unittest.main() From 81e7a6c2a8305068dc696a3e8e850865dff57a4c Mon Sep 17 00:00:00 2001 From: root Date: Sun, 24 May 2026 01:41:20 +0530 Subject: [PATCH 2/2] gh-132578: Add news blurb to Library and fix test layout spacing --- Lib/test/test_threading.py | 2 +- .../next/Library/2026-05-24-01-30-00.gh-issue-132578.aBcDeF.rst | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2026-05-24-01-30-00.gh-issue-132578.aBcDeF.rst diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py index ba8084630f38490..71756d64068be5d 100644 --- a/Lib/test/test_threading.py +++ b/Lib/test/test_threading.py @@ -2862,7 +2862,7 @@ def run(self): t = CustomThread() t.start() t.join() - + # Assert that our custom handle parameter was preserved and did not break the thread run lifecycle self.assertEqual(t._handle, "custom_third_party_handle_value") diff --git a/Misc/NEWS.d/next/Library/2026-05-24-01-30-00.gh-issue-132578.aBcDeF.rst b/Misc/NEWS.d/next/Library/2026-05-24-01-30-00.gh-issue-132578.aBcDeF.rst new file mode 100644 index 000000000000000..c4c926a97439958 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-05-24-01-30-00.gh-issue-132578.aBcDeF.rst @@ -0,0 +1 @@ +Add a regression test to ensure that custom user-defined subclasses of threading.Thread can safely define or override a custom _handle attribute without colliding with internal state-tracking implementations.