| 455 | } |
| 456 | |
| 457 | void 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 |
nothing calls this directly
no test coverage detected