From: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> Date: Wed, 3 Sep 2025 07:55:53 +0000 (+0200) Subject: gh-116946: add `Py_TPFLAGS_IMMUTABLETYPE` to `_random.Random` (#138341) X-Git-Tag: v3.15.0a1~523 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=51244ba16a7312945a60dff18ed155a581295fbf;p=thirdparty%2FPython%2Fcpython.git gh-116946: add `Py_TPFLAGS_IMMUTABLETYPE` to `_random.Random` (#138341) --- 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,