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 00000000000000..015cf24c8869f8 --- /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 2f4f388ce1161a..aa2fd28c232f28 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,