logo       

How do I subtype python internal type that is not part of a module?: msg#00034

python.pyrex

Subject: How do I subtype python internal type that is not part of a module?

I have enhanced my python interpeter to allow subtyping of python functions and
wish to create
some extension types directly from PyFunction_Type. Unfortunately the type is
not part of any
module. I have tried the following pyrex code:

# func.pyx
# Useful subtypes of function type.

cdef extern from "python.h":
ctypedef class function [object PyFunctionObject, type PyFunction_Type]:
pass
cdef object PyMethod_New(object func, object self, object type)

cdef class classfunction(function):
def __get__(self, obj, typ):
if typ is None:
typ = type(typ)
return PyMethod_New(self, typ, type(typ))

cdef class staticfunction(function):
def __get__(self, obj, typ):
return self

and it generates the following messages at compile time:

...\func.pyx:5:4: Module name required for 'extern' C class
...\func.pyx:5:4: Type object name specification not allowed for 'extern' C
class

I cannot give a module name because there is none; the python 'types' and 'new'
modules are
coded in python and use something like function = type(lambda: None) to get the
function type.
Even that does not work:

# func.pyx
# Useful subtypes of function type.

cdef extern from "python.h":
object PyMethod_New(object func, object self, object type)

function = type(lambda: None)
.
.
.

...\func.pyx:7:16: Expected an identifier or literal

Any suggestions?

Lenard Lindstrom
<len-l@xxxxxxxxx>


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise