Parcourir la source

add some docs

blueloveTH il y a 1 an
Parent
commit
a54c7e4b03
2 fichiers modifiés avec 28 ajouts et 0 suppressions
  1. 27 0
      docs/features/differences.md
  2. 1 0
      docs/modules/itertools.md

+ 27 - 0
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.
 10. `%`, `&`, `//`, `^` and `|` for `int` behave the same as C, not python.
 11. `str.split` and `str.splitlines` will remove all empty entries.
 11. `str.split` and `str.splitlines` will remove all empty entries.
 12. `__getattr__`, `__setattr__` and `__delattr__` can only be set in cpp.
 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.
+!!!

+ 1 - 0
docs/modules/itertools.md

@@ -5,3 +5,4 @@ label: itertools
 
 
 ### `itertools.zip_longest(a, b)`
 ### `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`.