中找到一个真实的例子
下面是我试图编译的cython文件的示例:
foobar.pxd
cdef extern from 'object.h':
ctypedef class __builtin__.type [object PyHeapTypeObject]:
pass
cdef class _A(type):
pass
cdef class A #Forward Declaration
cdef class B(A):
pass
foobar.pyx
cdef class _A(type):
def __init__(metaself, name, **args):
super(_A, metaself).__init__(name, *args)
print name
A = _A('A', (object,), {})
cdef class B(A):
pass
当我尝试编译它们时,我得到一个AnalyseDeclarationsTransform
错误。什么是合适的语法,或者有什么变通方法?
据我所知,你不能有一个扩展(cdef)类的元类,这不是type
。但是请注意,通常的类带有cdef元类是完全正确的。我不确定你想达到什么目的,但以下是可以的:
cdef extern from 'object.h':
ctypedef class __builtin__.type [object PyHeapTypeObject]:
pass
cdef class _A(type):
pass
和
cdef class _A(type):
def __init__(metaself, name, **args):
super(_A, metaself).__init__(name, *args)
print name
A = _A('A', (object,), {})
class B(A): # use a non cdef class
pass
你可以在sage的classcall_metacclass