Sublassing in C

D

Dennis Kaarsemaker

I'm trying to create a subclass of Exception in C, but cant figure out
what to use as tp_base in the PyTypeObject struct. Can anybody give me
directions on where to look or maybe even an answer?
 
D

David M. Cooke

At some point said:
I'm trying to create a subclass of Exception in C, but cant figure out
what to use as tp_base in the PyTypeObject struct. Can anybody give me
directions on where to look or maybe even an answer?

Have a look at Python/exceptions.c in the Python source; that's where
all the subclasses of Exception (IndexError, etc.) are created.
 
G

Greg Chapman

I'm trying to create a subclass of Exception in C, but cant figure out
what to use as tp_base in the PyTypeObject struct. Can anybody give me
directions on where to look or maybe even an answer?

Currently, exceptions have to be old-style classes, so you cannot create a
subclass using the new type-based subclassing. Instead, you should use
PyErr_NewException, which creates a new Exception subclass with the given name,
base and attributes (despite the first sentence of the documentation, it returns
a new subclass, not a new exception object).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top