bpo-43916: select.devpoll uses Py_TPFLAGS_DISALLOW_INSTANTIATION (GH-25751)

This commit is contained in:
Victor Stinner 2021-04-30 18:19:57 +02:00 committed by GitHub
parent 9746cda705
commit 7dcf0f6db3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 9 deletions

View file

@ -91,6 +91,10 @@ def test_disallow_instantiation(self):
tp = type(select.poll())
self.assertRaises(TypeError, tp)
if hasattr(select, 'devpoll'):
tp = type(select.devpoll())
self.assertRaises(TypeError, tp)
def tearDownModule():
support.reap_children()

View file

@ -1110,13 +1110,6 @@ newDevPollObject(PyObject *module)
return self;
}
static PyObject *
devpoll_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
{
PyErr_Format(PyExc_TypeError, "Cannot create '%.200s' instances", _PyType_Name(type));
return NULL;
}
static void
devpoll_dealloc(devpollObject *self)
{
@ -1131,7 +1124,6 @@ static PyType_Slot devpoll_Type_slots[] = {
{Py_tp_dealloc, devpoll_dealloc},
{Py_tp_getset, devpoll_getsetlist},
{Py_tp_methods, devpoll_methods},
{Py_tp_new, devpoll_new},
{0, 0},
};
@ -1139,7 +1131,7 @@ static PyType_Spec devpoll_Type_spec = {
"select.devpoll",
sizeof(devpollObject),
0,
Py_TPFLAGS_DEFAULT,
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION,
devpoll_Type_slots
};