1
0
mirror of https://github.com/exaloop/codon.git synced 2025-06-03 15:03:52 +08:00

Fix pyext iterators

This commit is contained in:
A. R. Shajii 2023-03-24 11:20:22 -04:00
parent 02873b909d
commit 2bd28c8385

View File

@ -1853,12 +1853,19 @@ class _PyWrap:
def _iter(obj: cobj) -> cobj:
T # need separate fn for each instantiation
p = Ptr[PyObject](obj)
o = p[0]
p[0] = PyObject(o.refcnt + 1, o.pytype)
return obj
def _iternext(self: cobj) -> cobj:
pt = _PyWrap.IterWrap[T].__from_py__(self)
if pt._gen == cobj():
return cobj()
gt = type(T().__iter__())(pt._gen)
if gt.done():
pt._gen = cobj()
return cobj()
else:
return gt.next().__to_py__()