Skip to content

Commit 387397f

Browse files
author
Erlend Egeberg Aasland
authored
bpo-43916: select.poll uses Py_TPFLAGS_DISALLOW_INSTANTIATION (GH-25750)
1 parent 5979e81 commit 387397f

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

Lib/test/test_select.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ def fileno(self):
8787
a[:] = [F()] * 10
8888
self.assertEqual(select.select([], a, []), ([], a[:5], []))
8989

90+
def test_disallow_instantiation(self):
91+
tp = type(select.poll())
92+
self.assertRaises(TypeError, tp)
93+
9094
def tearDownModule():
9195
support.reap_children()
9296

Modules/selectmodule.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -728,13 +728,6 @@ newPollObject(PyObject *module)
728728
return self;
729729
}
730730

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-
738731
static void
739732
poll_dealloc(pollObject *self)
740733
{
@@ -2275,16 +2268,14 @@ static PyMethodDef poll_methods[] = {
22752268
static PyType_Slot poll_Type_slots[] = {
22762269
{Py_tp_dealloc, poll_dealloc},
22772270
{Py_tp_methods, poll_methods},
2278-
{Py_tp_new, poll_new},
22792271
{0, 0},
22802272
};
22812273

22822274
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,
22882279
};
22892280

22902281
#ifdef HAVE_SYS_DEVPOLL_H

0 commit comments

Comments
 (0)