File: builtin_next.pyx

package info (click to toggle)
cython 3.0.11%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 19,092 kB
  • sloc: python: 83,539; ansic: 18,831; cpp: 1,402; xml: 1,031; javascript: 511; makefile: 403; sh: 204; sed: 11
file content (92 lines) | stat: -rw-r--r-- 1,661 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92

import sys
IS_PY3 = sys.version_info[0] >= 3

__doc__ = """
>>> it = iter([1,2,3])
>>> if not IS_PY3:
...     next = type(it).next
>>> next(it)
1
>>> next(it)
2
>>> next(it)
3

>>> next(it)
Traceback (most recent call last):
StopIteration

>>> next(it)
Traceback (most recent call last):
StopIteration

>>> if IS_PY3: next(it, 123)
... else: print(123)
123
"""

if IS_PY3:
    __doc__ += """
>>> next(123)      # doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError: ...int... object is not an iterator
"""

def test_next_not_iterable(it):
    """
    >>> test_next_not_iterable(123)
    Traceback (most recent call last):
    TypeError: int object is not an iterator
    """
    return next(it)

def test_single_next(it):
    """
    >>> it = iter([1,2,3])
    >>> test_single_next(it)
    1
    >>> test_single_next(it)
    2
    >>> test_single_next(it)
    3
    >>> test_single_next(it)
    Traceback (most recent call last):
    StopIteration
    >>> test_single_next(it)
    Traceback (most recent call last):
    StopIteration
    """
    return next(it)

def test_default_next(it, default):
    """
    >>> it = iter([1,2,3])
    >>> test_default_next(it, 99)
    1
    >>> test_default_next(it, 99)
    2
    >>> test_default_next(it, 99)
    3
    >>> test_default_next(it, 99)
    99
    >>> test_default_next(it, 99)
    99
    """
    return next(it, default)

def test_next_override(it):
    """
    >>> it = iter([1,2,3])
    >>> test_next_override(it)
    1
    >>> test_next_override(it)
    1
    >>> test_next_override(it)
    1
    >>> test_next_override(it)
    1
    """
    def next(it):
        return 1
    return next(it)