Commit b1d7b0de authored by Robert Bradshaw's avatar Robert Bradshaw

Declare Exception as a builtin type.

This allows extending from it with a cdef class. Closes #724.
parent ce9b4f5c
......@@ -324,6 +324,7 @@ builtin_types_table = [
BuiltinMethod("add", "TO", "r", "PySet_Add"),
BuiltinMethod("pop", "T", "O", "PySet_Pop")]),
("frozenset", "PyFrozenSet_Type", []),
("Exception", "((PyTypeObject*)PyExc_Exception)[0]", []),
]
......@@ -377,6 +378,8 @@ def init_builtin_types():
objstruct_cname = 'PySetObject'
elif name == 'bool':
objstruct_cname = None
elif name == 'Exception':
objstruct_cname = "PyBaseExceptionObject"
else:
objstruct_cname = 'Py%sObject' % name.capitalize()
the_type = builtin_scope.declare_builtin_type(name, cname, utility, objstruct_cname)
......
......@@ -114,3 +114,14 @@ cdef class MyDict(dict):
True
"""
cdef readonly object attr
cdef class MyException(Exception):
"""
>>> raise MyException(3)
Traceback (most recent call last):
...
MyException: 3
"""
cdef readonly int value
def __cinit__(self, value):
self.value = value
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment