我正在与 Cython 合作,为一个大学项目优化我的 Python 代码。为此,我想将 python 类转换为扩展类型。我目前在编译一种扩展类型时遇到问题,该扩展类型应该是另一种扩展类型的子类。这是我得到的错误:
src/core/ast/ast_classes/AstPreprocessor.pyx:9:27: First base of 'AstPreprocessor' is not an extension type
Run Code Online (Sandbox Code Playgroud)
AstPreprocessor的定义如下:
#Edit
from src.core.ast.ast_classes.AstBase import AstBase
cdef class AstPreprocessor(AstBase):
cdef str function_name
def __init__(self, function_ast, str function_name):
super().__init__(function_ast)
self.ast.index = self.ast.index.map(str)
self.function_name = function_name
self.symbol_list = super().get_symbol_list(self.function_name)
#more method declarations
Run Code Online (Sandbox Code Playgroud)
这是 AstBase 类的一部分,包括 中调用的方法AstPreprocessor#__init__():
cdef class AstBase:
cdef int length
def __init__(self, df):
self.ast = df
self.length = int(df.shape[0])
self.childrens = {}
#more method declarations
cdef get_symbol_list(self, str function_name): …Run Code Online (Sandbox Code Playgroud)