Код: Выделить всё
import xxsubtype
s = xxsubstype.spamtuple((1,2,3))
Код: Выделить всё
static PyObject *
spamtuple_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
spamtupleobject *self;
self = (spamtupleobject *)PyTuple_Type.tp_new(type, args, kwds);
if (self != NULL) {
self->state = 0; // Initialize custom attributes
}
return (PyObject *)self;
}
Код: Выделить всё
static PyTypeObject spamtuple_type = {
PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0)
"xxsubtype.spamtuple",
sizeof(spamtupleobject),
0,
0, /* tp_dealloc */
...
(initproc)spamtuple_init, /* tp_init */
0, /* tp_alloc */
spamtuple_new, /* tp_new */
};
Код: Выделить всё
s = xxsubstype.spamtuple((1,2,3))
Код: Выделить всё
s = xxsubtype.spamtuple((1,2,3), data=data)
Подробнее здесь: https://stackoverflow.com/questions/791 ... ple-templa