Author here: Note that this hasn't yet been updated for Cython 3, which does fix or improve some of these (but not the fundamental limitation that you're stuck with C or C++).
from libcpp.vector cimport vector
from libcpp.pair cimport pair
cdef class PointVec:
cdef vector[pair[float, float]] vec
def __init__(self, points: list[tuple[float, float]]):
self.vec = points
def __repr__(self):
result = ", ".join(f"({x}, {y})" for x, y in self.vec)
return f"PointVec({result})"
def __setitem__(
self, index, point: tuple[float, float]
):
cdef pair[float, float] *p = &self.vec.at(index)
p.first = point[0]
p.second = point[1]
def __getitem__(self, index):
return self.vec.at(index)Opt-in safety is clearly worse than opt-out safety.