]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-116946: add `Py_TPFLAGS_IMMUTABLETYPE` to `_random.Random` (#138341)
authorBénédikt Tran <10796600+picnixz@users.noreply.github.com>
Wed, 3 Sep 2025 07:55:53 +0000 (09:55 +0200)
committerGitHub <noreply@github.com>
Wed, 3 Sep 2025 07:55:53 +0000 (09:55 +0200)
Misc/NEWS.d/next/Library/2025-09-02-10-23-09.gh-issue-116946.U6RpwK.rst [new file with mode: 0644]
Modules/_randommodule.c

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 (file)
index 0000000..015cf24
--- /dev/null
@@ -0,0 +1,2 @@
+The :class:`!_random.Random` C type is now immutable. Patch by Bénédikt
+Tran.
index 2f4f388ce1161ab6e282438f251b122dafd52c70..aa2fd28c232f287c094ffcef232a4ef2ab162d80 100644 (file)
@@ -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,