cython的通用类

I want to make a class, parametrized on T, like so:


from libcpp.vector cimport vector

cdef class Thing[T]:
    cdef vector[T] c_vector

    def __init__(self, data):
        self.c_vector = data

    def get_first(self):
        return self.c_vector[0]  

我收到一个错误:

rimes.pyx:32:17: Expected 'object', 'type' or 'check_size'
Traceback (most recent call last):
  File "setup.py", line 4, in <module>
    setup(ext_modules=cythonize("*.pyx", language_level="3"))
  File "/usr/local/lib/python3.7/site-packages/Cython/Build/Dependencies.py", line 1102, in cythonize
    cythonize_one(*args)
  File "/usr/local/lib/python3.7/site-packages/Cython/Build/Dependencies.py", line 1225, in cythonize_one
    raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: primes.pyx
评论