bpo-43916: select.poll uses Py_TPFLAGS_DISALLOW_INSTANTIATION (GH-25750) · python/cpython@387397f (original) (raw)

2 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -87,6 +87,10 @@ def fileno(self):
87 87 a[:] = [F()] * 10
88 88 self.assertEqual(select.select([], a, []), ([], a[:5], []))
89 89
90 +def test_disallow_instantiation(self):
91 +tp = type(select.poll())
92 +self.assertRaises(TypeError, tp)
93 +
90 94 def tearDownModule():
91 95 support.reap_children()
92 96
Original file line number Diff line number Diff line change
@@ -728,13 +728,6 @@ newPollObject(PyObject *module)
728 728 return self;
729 729 }
730 730
731 -static PyObject *
732 -poll_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
733 -{
734 -PyErr_Format(PyExc_TypeError, "Cannot create '%.200s' instances", _PyType_Name(type));
735 -return NULL;
736 -}
737 -
738 731 static void
739 732 poll_dealloc(pollObject *self)
740 733 {
@@ -2275,16 +2268,14 @@ static PyMethodDef poll_methods[] = {
2275 2268 static PyType_Slot poll_Type_slots[] = {
2276 2269 {Py_tp_dealloc, poll_dealloc},
2277 2270 {Py_tp_methods, poll_methods},
2278 - {Py_tp_new, poll_new},
2279 2271 {0, 0},
2280 2272 };
2281 2273
2282 2274 static PyType_Spec poll_Type_spec = {
2283 -"select.poll",
2284 -sizeof(pollObject),
2285 -0,
2286 -Py_TPFLAGS_DEFAULT,
2287 -poll_Type_slots
2275 + .name = "select.poll",
2276 + .basicsize = sizeof(pollObject),
2277 + .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION,
2278 + .slots = poll_Type_slots,
2288 2279 };
2289 2280
2290 2281 #ifdef HAVE_SYS_DEVPOLL_H