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:
parent
02873b909d
commit
2bd28c8385
@ -1853,12 +1853,19 @@ class _PyWrap:
|
|||||||
|
|
||||||
def _iter(obj: cobj) -> cobj:
|
def _iter(obj: cobj) -> cobj:
|
||||||
T # need separate fn for each instantiation
|
T # need separate fn for each instantiation
|
||||||
|
p = Ptr[PyObject](obj)
|
||||||
|
o = p[0]
|
||||||
|
p[0] = PyObject(o.refcnt + 1, o.pytype)
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
def _iternext(self: cobj) -> cobj:
|
def _iternext(self: cobj) -> cobj:
|
||||||
pt = _PyWrap.IterWrap[T].__from_py__(self)
|
pt = _PyWrap.IterWrap[T].__from_py__(self)
|
||||||
|
if pt._gen == cobj():
|
||||||
|
return cobj()
|
||||||
|
|
||||||
gt = type(T().__iter__())(pt._gen)
|
gt = type(T().__iter__())(pt._gen)
|
||||||
if gt.done():
|
if gt.done():
|
||||||
|
pt._gen = cobj()
|
||||||
return cobj()
|
return cobj()
|
||||||
else:
|
else:
|
||||||
return gt.next().__to_py__()
|
return gt.next().__to_py__()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user