How are you supposed to define subclasses in C?

Zachary Ware zachary.ware+pylist at gmail.com
Thu Apr 21 12:39:09 EDT 2016


On Thu, Apr 21, 2016 at 11:35 AM, Random832 <random832 at fastmail.com> wrote:
> I was trying to write a proof of concept on including descriptors (e.g.
> a "sys.recursionlimit" instead of set/get methods) in the sys module,
> and couldn't figure out how to "properly" define a type using
> PyType_FromSpecWithBases. Everything I tried just segfaulted. I ended up
> just calling PyObject_CallFunctionObjArgs((PyObject *)&PyType_Type, ...)
> but I assume there's a better way to do it. I couldn't find any examples
> or tutorial.

Have a look at https://hg.python.org/cpython/file/default/Modules/xxsubtype.c

-- 
Zach



More information about the Python-list mailing list