MCPcopy Create free account
hub / github.com/alibaba/zvec / bind_iterator

Method bind_iterator

src/binding/python/model/python_collection.cc:457–480  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

455}
456
457void ZVecPyCollection::bind_iterator(py::module_ &m) {
458 // Document iterator: Python iterator protocol (__iter__ / __next__).
459 // Constructed only via Collection.create_iterator (no py::init).
460 py::class_<DocIterator, DocIterator::Ptr>(m, "_DocIterator")
461 .def("__iter__", [](py::object self) { return self; })
462 .def("__next__",
463 [](DocIterator &self) {
464 Result<Doc::Ptr> result;
465 {
466 py::gil_scoped_release release;
467 result = self.next();
468 }
469 // !has_value() -> error (raises); value()==nullptr -> EOF
470 auto doc = unwrap_expected(result);
471 if (doc == nullptr) {
472 throw py::stop_iteration();
473 }
474 return doc;
475 })
476 .def("close", [](DocIterator &self) {
477 py::gil_scoped_release release;
478 self.close();
479 });
480}
481
482} // namespace zvec

Callers

nothing calls this directly

Calls 3

unwrap_expectedFunction · 0.85
nextMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected