https://github.com/python/cpython/commit/3ff00c76c9b02d56b448e1d2669ad9f154b427b3
commit: 3ff00c76c9b02d56b448e1d2669ad9f154b427b3
branch: main
author: Bénédikt Tran <10796600+picn...@users.noreply.github.com>
committer: kumaraditya303 <kumaradi...@python.org>
date: 2025-09-02T17:53:44Z
summary:

gh-116946: add `Py_TPFLAGS_IMMUTABLETYPE` to `select.poll` and `select.epoll` 
(#138340)

files:
A Misc/NEWS.d/next/Library/2025-09-02-10-27-21.gh-issue-116946.VxXNGD.rst
M Modules/selectmodule.c

diff --git 
a/Misc/NEWS.d/next/Library/2025-09-02-10-27-21.gh-issue-116946.VxXNGD.rst 
b/Misc/NEWS.d/next/Library/2025-09-02-10-27-21.gh-issue-116946.VxXNGD.rst
new file mode 100644
index 00000000000000..bb56cbb3fefaf4
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-09-02-10-27-21.gh-issue-116946.VxXNGD.rst
@@ -0,0 +1,2 @@
+The types of :func:`select.poll` and :func:`select.epoll` objects are now
+immutable. Patch by Bénédikt Tran.
diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c
index 99d96ebed2f7b1..107e674907cf73 100644
--- a/Modules/selectmodule.c
+++ b/Modules/selectmodule.c
@@ -433,7 +433,7 @@ select_select_impl(PyObject *module, PyObject *rlist, 
PyObject *wlist,
 
 typedef struct {
     PyObject_HEAD
-    PyObject *dict;
+    PyObject *dict;     // cannot create cycles as it only contains exact ints
     int ufd_uptodate;
     int ufd_len;
     struct pollfd *ufds;
@@ -2483,7 +2483,11 @@ static PyType_Slot poll_Type_slots[] = {
 static PyType_Spec poll_Type_spec = {
     .name = "select.poll",
     .basicsize = sizeof(pollObject),
-    .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION,
+    .flags = (
+        Py_TPFLAGS_DEFAULT
+        | Py_TPFLAGS_DISALLOW_INSTANTIATION
+        | Py_TPFLAGS_IMMUTABLETYPE
+    ),
     .slots = poll_Type_slots,
 };
 
@@ -2529,11 +2533,10 @@ static PyType_Slot pyEpoll_Type_slots[] = {
 };
 
 static PyType_Spec pyEpoll_Type_spec = {
-    "select.epoll",
-    sizeof(pyEpoll_Object),
-    0,
-    Py_TPFLAGS_DEFAULT,
-    pyEpoll_Type_slots
+    .name = "select.epoll",
+    .basicsize = sizeof(pyEpoll_Object),
+    .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE,
+    .slots = pyEpoll_Type_slots
 };
 
 #endif /* HAVE_EPOLL */

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: arch...@mail-archive.com

Reply via email to