From a54c7e4b034f01386fd951bc01a76e0ba45a715b Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sun, 14 Apr 2024 00:17:02 +0800 Subject: [PATCH] add some docs --- docs/features/differences.md | 27 +++++++++++++++++++++++++++ docs/modules/itertools.md | 1 + 2 files changed, 28 insertions(+) diff --git a/docs/features/differences.md b/docs/features/differences.md index 90a66194..338c68ed 100644 --- a/docs/features/differences.md +++ b/docs/features/differences.md @@ -41,3 +41,30 @@ The easiest way to test a feature is to [try it on your browser](https://pocketp 10. `%`, `&`, `//`, `^` and `|` for `int` behave the same as C, not python. 11. `str.split` and `str.splitlines` will remove all empty entries. 12. `__getattr__`, `__setattr__` and `__delattr__` can only be set in cpp. + +### Make `next()` compatible with cpython + +You can use the following code to make `next()` compatible with cpython temporarily. + +```python +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 +``` + +!!! +Do not change `builtins.next`. It will break some internal functions which rely on `StopIteration` as return value. +!!! \ No newline at end of file diff --git a/docs/modules/itertools.md b/docs/modules/itertools.md index d92de079..cafa14a0 100644 --- a/docs/modules/itertools.md +++ b/docs/modules/itertools.md @@ -5,3 +5,4 @@ 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`.