mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
allow next
to be compatible with cpython (#241)
* add `itertools` * Update _generated.h * allow `next` to be compatible with cpython
This commit is contained in:
parent
cacc7274f7
commit
4d2af4b83d
@ -729,7 +729,7 @@ void VM::init_builtin_types(){
|
|||||||
this->Ellipsis = heap._new<Dummy>(_new_type_object("ellipsis"));
|
this->Ellipsis = heap._new<Dummy>(_new_type_object("ellipsis"));
|
||||||
this->True = heap._new<Dummy>(tp_bool);
|
this->True = heap._new<Dummy>(tp_bool);
|
||||||
this->False = heap._new<Dummy>(tp_bool);
|
this->False = heap._new<Dummy>(tp_bool);
|
||||||
this->StopIteration = heap._new<Dummy>(_new_type_object("StopIterationType"));
|
this->StopIteration = _all_types[_new_type_object("StopIteration", tp_exception)].obj;
|
||||||
|
|
||||||
this->builtins = new_module("builtins");
|
this->builtins = new_module("builtins");
|
||||||
|
|
||||||
|
@ -36,3 +36,21 @@ assert next(i) == 4
|
|||||||
assert next(i) == 5
|
assert next(i) == 5
|
||||||
assert next(i) == StopIteration
|
assert next(i) == StopIteration
|
||||||
assert next(i) == StopIteration
|
assert next(i) == StopIteration
|
||||||
|
|
||||||
|
import builtins
|
||||||
|
|
||||||
|
def next(obj):
|
||||||
|
res = builtins.next(obj)
|
||||||
|
if res is StopIteration:
|
||||||
|
raise StopIteration
|
||||||
|
return res
|
||||||
|
|
||||||
|
a = iter([1])
|
||||||
|
assert next(a) == 1
|
||||||
|
|
||||||
|
try:
|
||||||
|
next(a)
|
||||||
|
exit(1)
|
||||||
|
except StopIteration:
|
||||||
|
pass
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user