]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-43916: select.poll uses Py_TPFLAGS_DISALLOW_INSTANTIATION (GH-25750)
authorErlend Egeberg Aasland <erlend.aasland@innova.no>
Fri, 30 Apr 2021 13:49:17 +0000 (15:49 +0200)
committerGitHub <noreply@github.com>
Fri, 30 Apr 2021 13:49:17 +0000 (15:49 +0200)
Lib/test/test_select.py
Modules/selectmodule.c

index f63564e6b0ee6dc180829c4c2658b85db98dca37..1ef5624354987466a963a7a352162e974d13422b 100644 (file)
@@ -87,6 +87,10 @@ class SelectTestCase(unittest.TestCase):
         a[:] = [F()] * 10
         self.assertEqual(select.select([], a, []), ([], a[:5], []))
 
+    def test_disallow_instantiation(self):
+        tp = type(select.poll())
+        self.assertRaises(TypeError, tp)
+
 def tearDownModule():
     support.reap_children()
 
index f80da5895401feb4bebce8501e1425c003a7674f..5038c325faa4eb77e0cd3be867aa15a394935338 100644 (file)
@@ -728,13 +728,6 @@ newPollObject(PyObject *module)
     return self;
 }
 
-static PyObject *
-poll_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
-{
-    PyErr_Format(PyExc_TypeError, "Cannot create '%.200s' instances", _PyType_Name(type));
-    return NULL;
-}
-
 static void
 poll_dealloc(pollObject *self)
 {
@@ -2275,16 +2268,14 @@ static PyMethodDef poll_methods[] = {
 static PyType_Slot poll_Type_slots[] = {
     {Py_tp_dealloc, poll_dealloc},
     {Py_tp_methods, poll_methods},
-    {Py_tp_new, poll_new},
     {0, 0},
 };
 
 static PyType_Spec poll_Type_spec = {
-    "select.poll",
-    sizeof(pollObject),
-    0,
-    Py_TPFLAGS_DEFAULT,
-    poll_Type_slots
+    .name = "select.poll",
+    .basicsize = sizeof(pollObject),
+    .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION,
+    .slots = poll_Type_slots,
 };
 
 #ifdef HAVE_SYS_DEVPOLL_H