X Tutup
Skip to content

Commit 35cbf16

Browse files
committed
Make doctests pass in the functional howto.
1 parent 45a101d commit 35cbf16

File tree

1 file changed

+17
-26
lines changed

1 file changed

+17
-26
lines changed

Doc/howto/functional.rst

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ You can experiment with the iteration interface manually:
198198

199199
>>> L = [1,2,3]
200200
>>> it = iter(L)
201-
>>> it
201+
>>> it #doctest: +ELLIPSIS
202202
<...iterator object at ...>
203203
>>> it.__next__() # same as next(it)
204204
1
@@ -267,15 +267,11 @@ sequence type, such as strings, will automatically support creation of an
267267
iterator.
268268

269269
Calling :func:`iter` on a dictionary returns an iterator that will loop over the
270-
dictionary's keys:
271-
272-
.. not a doctest since dict ordering varies across Pythons
273-
274-
::
270+
dictionary's keys::
275271

276272
>>> m = {'Jan': 1, 'Feb': 2, 'Mar': 3, 'Apr': 4, 'May': 5, 'Jun': 6,
277273
... 'Jul': 7, 'Aug': 8, 'Sep': 9, 'Oct': 10, 'Nov': 11, 'Dec': 12}
278-
>>> for key in m:
274+
>>> for key in m: #doctest: +SKIP
279275
... print(key, m[key])
280276
Mar 3
281277
Feb 2
@@ -410,12 +406,9 @@ clauses, the length of the resulting output will be equal to the product of the
410406
lengths of all the sequences. If you have two lists of length 3, the output
411407
list is 9 elements long:
412408

413-
.. doctest::
414-
:options: +NORMALIZE_WHITESPACE
415-
416409
>>> seq1 = 'abc'
417410
>>> seq2 = (1,2,3)
418-
>>> [(x, y) for x in seq1 for y in seq2]
411+
>>> [(x, y) for x in seq1 for y in seq2] #doctest: +NORMALIZE_WHITESPACE
419412
[('a', 1), ('a', 2), ('a', 3),
420413
('b', 1), ('b', 2), ('b', 3),
421414
('c', 1), ('c', 2), ('c', 3)]
@@ -448,11 +441,9 @@ is what generators provide; they can be thought of as resumable functions.
448441

449442
Here's the simplest example of a generator function:
450443

451-
.. testcode::
452-
453-
def generate_ints(N):
454-
for i in range(N):
455-
yield i
444+
>>> def generate_ints(N):
445+
... for i in range(N):
446+
... yield i
456447

457448
Any function containing a :keyword:`yield` keyword is a generator function;
458449
this is detected by Python's :term:`bytecode` compiler which compiles the
@@ -470,7 +461,7 @@ executing.
470461
Here's a sample usage of the ``generate_ints()`` generator:
471462

472463
>>> gen = generate_ints(3)
473-
>>> gen
464+
>>> gen #doctest: +ELLIPSIS
474465
<generator object generate_ints at ...>
475466
>>> next(gen)
476467
0
@@ -575,16 +566,16 @@ the internal counter.
575566

576567
And here's an example of changing the counter:
577568

578-
>>> it = counter(10)
579-
>>> next(it)
569+
>>> it = counter(10) #doctest: +SKIP
570+
>>> next(it) #doctest: +SKIP
580571
0
581-
>>> next(it)
572+
>>> next(it) #doctest: +SKIP
582573
1
583-
>>> it.send(8)
574+
>>> it.send(8) #doctest: +SKIP
584575
8
585-
>>> next(it)
576+
>>> next(it) #doctest: +SKIP
586577
9
587-
>>> next(it)
578+
>>> next(it) #doctest: +SKIP
588579
Traceback (most recent call last):
589580
File "t.py", line 15, in ?
590581
it.next()
@@ -687,11 +678,11 @@ constructed list's :meth:`~list.sort` method. ::
687678
>>> import random
688679
>>> # Generate 8 random numbers between [0, 10000)
689680
>>> rand_list = random.sample(range(10000), 8)
690-
>>> rand_list
681+
>>> rand_list #doctest: +SKIP
691682
[769, 7953, 9828, 6431, 8442, 9878, 6213, 2207]
692-
>>> sorted(rand_list)
683+
>>> sorted(rand_list) #doctest: +SKIP
693684
[769, 2207, 6213, 6431, 7953, 8442, 9828, 9878]
694-
>>> sorted(rand_list, reverse=True)
685+
>>> sorted(rand_list, reverse=True) #doctest: +SKIP
695686
[9878, 9828, 8442, 7953, 6431, 6213, 2207, 769]
696687

697688
(For a more detailed discussion of sorting, see the :ref:`sortinghowto`.)

0 commit comments

Comments
 (0)
X Tutup