Skip to content
Open
Show file tree
Hide file tree
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
44 changes: 24 additions & 20 deletions Modules/_collectionsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ find_module_state_by_def(PyTypeObject *type)
module _collections
class _tuplegetter "_tuplegetterobject *" "clinic_state()->tuplegetter_type"
class _collections.deque "dequeobject *" "clinic_state()->deque_type"
class _collections.defaultdict "PyObject *" "type"
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=a033cc2a8476b3f1]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=3488c614fa7c6bd5]*/

typedef struct dequeobject dequeobject;

Expand Down Expand Up @@ -2455,32 +2456,34 @@ defdict_tp_clear(PyObject *op)
return PyDict_Type.tp_clear(op);
}

/*[clinic input]
@vectorcall
_collections.defaultdict.__init__ as defdict_init
default_factory: object = None
/
*args: tuple
**kwargs: dict
[clinic start generated code]*/

static int
defdict_init(PyObject *self, PyObject *args, PyObject *kwds)
defdict_init_impl(PyObject *self, PyObject *default_factory, PyObject *args,
PyObject *kwargs)
/*[clinic end generated code: output=af68ec37fc3b209b input=3809f9457f1187f1]*/
{
defdictobject *dd = defdictobject_CAST(self);
PyObject *olddefault = dd->default_factory;
PyObject *newdefault = NULL;
PyObject *newargs;
int result;
if (args == NULL || !PyTuple_Check(args))
newargs = PyTuple_New(0);
else {
Py_ssize_t n = PyTuple_GET_SIZE(args);
if (n > 0) {
newdefault = PyTuple_GET_ITEM(args, 0);
if (!PyCallable_Check(newdefault) && newdefault != Py_None) {
PyErr_SetString(PyExc_TypeError,
"first argument must be callable or None");
return -1;
}
}
newargs = PySequence_GetSlice(args, 1, n);
}
if (newargs == NULL)

if (!PyCallable_Check(default_factory) && default_factory != Py_None) {
PyErr_SetString(PyExc_TypeError,
"first argument must be callable or None");
return -1;
dd->default_factory = Py_XNewRef(newdefault);
result = PyDict_Type.tp_init(self, newargs, kwds);
}
newargs = Py_NewRef(args);

dd->default_factory = Py_NewRef(default_factory);
result = PyDict_Type.tp_init(self, newargs, kwargs);
Py_DECREF(newargs);
Py_XDECREF(olddefault);
return result;
Expand Down Expand Up @@ -2511,6 +2514,7 @@ static PyType_Slot defdict_slots[] = {
{Py_tp_methods, defdict_methods},
{Py_tp_members, defdict_members},
{Py_tp_init, defdict_init},
{Py_tp_vectorcall, defdict_vectorcall},
{Py_tp_alloc, PyType_GenericAlloc},
{Py_tp_free, PyObject_GC_Del},
{0, NULL},
Expand Down
91 changes: 89 additions & 2 deletions Modules/clinic/_collectionsmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading