Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Make _struct.unpack_iterator type use type flag instead of custom i…
…terator

* remove `unpackiter_new` function
* remove item from `unpackiter_type_slots`
* add `Py_TPFLAGS_DISALLOW_INSTANTIATION` to type flags
  • Loading branch information
chgnrdv committed May 7, 2023
commit 734452c9ca9be17055a4a7841075d8b3d86374b7
8 changes: 1 addition & 7 deletions Modules/_struct.c
Original file line number Diff line number Diff line change
Expand Up @@ -1832,19 +1832,13 @@ unpackiter_iternext(unpackiterobject *self)
return result;
}

PyObject *unpackiter_new(PyTypeObject *type, PyObject *args, PyObject *kwds) {
PyErr_Format(PyExc_TypeError, "Cannot create '%.200s objects", _PyType_Name(type));
return NULL;
}

static PyType_Slot unpackiter_type_slots[] = {
{Py_tp_dealloc, unpackiter_dealloc},
{Py_tp_getattro, PyObject_GenericGetAttr},
{Py_tp_traverse, unpackiter_traverse},
{Py_tp_iter, PyObject_SelfIter},
{Py_tp_iternext, unpackiter_iternext},
{Py_tp_methods, unpackiter_methods},
{Py_tp_new, unpackiter_new},
{0, 0},
};

Expand All @@ -1853,7 +1847,7 @@ static PyType_Spec unpackiter_type_spec = {
sizeof(unpackiterobject),
0,
(Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_IMMUTABLETYPE),
Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_DISALLOW_INSTANTIATION),
unpackiter_type_slots
};

Expand Down