From 51244ba16a7312945a60dff18ed155a581295fbf Mon Sep 17 00:00:00 2001 From: =?utf8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Wed, 3 Sep 2025 09:55:53 +0200 Subject: [PATCH] gh-116946: add `Py_TPFLAGS_IMMUTABLETYPE` to `_random.Random` (#138341) --- .../2025-09-02-10-23-09.gh-issue-116946.U6RpwK.rst | 2 ++ Modules/_randommodule.c | 13 ++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2025-09-02-10-23-09.gh-issue-116946.U6RpwK.rst diff --git a/Misc/NEWS.d/next/Library/2025-09-02-10-23-09.gh-issue-116946.U6RpwK.rst b/Misc/NEWS.d/next/Library/2025-09-02-10-23-09.gh-issue-116946.U6RpwK.rst new file mode 100644 index 000000000000..015cf24c8869 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-09-02-10-23-09.gh-issue-116946.U6RpwK.rst @@ -0,0 +1,2 @@ +The :class:`!_random.Random` C type is now immutable. Patch by Bénédikt +Tran. diff --git a/Modules/_randommodule.c b/Modules/_randommodule.c index 2f4f388ce116..aa2fd28c232f 100644 --- a/Modules/_randommodule.c +++ b/Modules/_randommodule.c @@ -595,11 +595,14 @@ static PyType_Slot Random_Type_slots[] = { }; static PyType_Spec Random_Type_spec = { - "_random.Random", - sizeof(RandomObject), - 0, - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - Random_Type_slots + .name = "_random.Random", + .basicsize = sizeof(RandomObject), + .flags = ( + Py_TPFLAGS_DEFAULT + | Py_TPFLAGS_BASETYPE + | Py_TPFLAGS_IMMUTABLETYPE + ), + .slots = Random_Type_slots }; PyDoc_STRVAR(module_doc, -- 2.47.3