mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-19 19:10:17 +00:00
remove pkpy.next
This commit is contained in:
parent
62c12981df
commit
24a7e6f060
@ -1,8 +0,0 @@
|
||||
---
|
||||
icon: package
|
||||
label: itertools
|
||||
---
|
||||
|
||||
### `itertools.zip_longest(a, b)`
|
||||
|
||||
Returns an iterator that aggregates elements from the input iterables. If the input iterables are of different lengths, missing values are filled-in with `None`.
|
@ -11,7 +11,6 @@ extern const char kPythonLibs_dataclasses[];
|
||||
extern const char kPythonLibs_datetime[];
|
||||
extern const char kPythonLibs_functools[];
|
||||
extern const char kPythonLibs_heapq[];
|
||||
extern const char kPythonLibs_itertools[];
|
||||
extern const char kPythonLibs_operator[];
|
||||
extern const char kPythonLibs_pickle[];
|
||||
extern const char kPythonLibs_this[];
|
||||
|
@ -66,7 +66,7 @@ class mat3x3:
|
||||
|
||||
def __invert__(self) -> mat3x3: ...
|
||||
|
||||
def matmul(self, other: mat3x3, out: mat3x3 = None) -> mat3x3 | None: ...
|
||||
def matmul(self, other: mat3x3, out: mat3x3) -> mat3x3 | None: ...
|
||||
def determinant(self) -> float: ...
|
||||
|
||||
def copy(self) -> mat3x3: ...
|
||||
|
@ -1,4 +1 @@
|
||||
from typing import Any
|
||||
|
||||
def next(iter) -> Any | StopIteration:
|
||||
...
|
||||
|
@ -1,5 +1,3 @@
|
||||
from pkpy import next as __pkpy_next
|
||||
|
||||
def all(iterable):
|
||||
for i in iterable:
|
||||
if not i:
|
||||
@ -37,9 +35,10 @@ def zip(a, b):
|
||||
a = iter(a)
|
||||
b = iter(b)
|
||||
while True:
|
||||
ai = __pkpy_next(a)
|
||||
bi = __pkpy_next(b)
|
||||
if ai is StopIteration or bi is StopIteration:
|
||||
try:
|
||||
ai = next(a)
|
||||
bi = next(b)
|
||||
except StopIteration:
|
||||
break
|
||||
yield ai, bi
|
||||
|
||||
|
@ -1,15 +0,0 @@
|
||||
from pkpy import next
|
||||
|
||||
def zip_longest(a, b):
|
||||
a = iter(a)
|
||||
b = iter(b)
|
||||
while True:
|
||||
ai = next(a)
|
||||
bi = next(b)
|
||||
if ai is StopIteration and bi is StopIteration:
|
||||
break
|
||||
if ai is StopIteration:
|
||||
ai = None
|
||||
if bi is StopIteration:
|
||||
bi = None
|
||||
yield ai, bi
|
File diff suppressed because one or more lines are too long
@ -1,21 +1,5 @@
|
||||
#include "pocketpy/pocketpy.h"
|
||||
|
||||
#include "pocketpy/common/utils.h"
|
||||
#include "pocketpy/objects/object.h"
|
||||
#include "pocketpy/common/sstream.h"
|
||||
#include "pocketpy/interpreter/vm.h"
|
||||
|
||||
static bool pkpy_next(int argc, py_Ref argv) {
|
||||
PY_CHECK_ARGC(1);
|
||||
int res = py_next(argv);
|
||||
if(res == -1) return false;
|
||||
if(res) return true;
|
||||
py_assign(py_retval(), py_tpobject(tp_StopIteration));
|
||||
return true;
|
||||
}
|
||||
|
||||
void pk__add_module_pkpy() {
|
||||
py_Ref mod = py_newmodule("pkpy");
|
||||
|
||||
py_bindfunc(mod, "next", pkpy_next);
|
||||
py_newmodule("pkpy");
|
||||
}
|
@ -1,13 +1,12 @@
|
||||
from pkpy import next
|
||||
|
||||
a = [1, 2, 3]
|
||||
a = iter(a)
|
||||
|
||||
total = 0
|
||||
|
||||
while True:
|
||||
obj = next(a)
|
||||
if obj is StopIteration:
|
||||
try:
|
||||
obj = next(a)
|
||||
except StopIteration:
|
||||
break
|
||||
total += obj
|
||||
|
||||
@ -36,11 +35,11 @@ assert next(i) == 2
|
||||
assert next(i) == 3
|
||||
assert next(i) == 4
|
||||
assert next(i) == 5
|
||||
assert next(i) == StopIteration
|
||||
assert next(i) == StopIteration
|
||||
|
||||
# test normal next
|
||||
from builtins import next
|
||||
try:
|
||||
next(i)
|
||||
exit(1)
|
||||
except StopIteration:
|
||||
pass
|
||||
|
||||
a = iter([1])
|
||||
assert next(a) == 1
|
||||
|
@ -1,6 +0,0 @@
|
||||
from itertools import zip_longest
|
||||
|
||||
a = [1, 2, 3]
|
||||
b = [2]
|
||||
|
||||
assert list(zip_longest(a, b)) == [(1, 2), (2, None), (3, None)]
|
Loading…
x
Reference in New Issue
Block a user