<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">On 01/27/2014 06:26 PM, Vajrasky Kok
wrote:<br>
</div>
<blockquote type="cite">
<pre wrap="">So I believe the doc fix is required then.</pre>
</blockquote>
<br>
<br>
I propose the docstring should describe only supported behavior, and
the docs in the manual should mention the unsupported behavior.
However, I'm interested in Raymond's take, as he's the original
author of itertools.repeat.<br>
<br>
<br>
If I were writing it, it might well come out like this:<br>
<br>
<br>
docstring:<br>
<br>
<blockquote>repeat(object [,times]) -> iterator<br>
<br>
Return an iterator which yields the object for the specified
number of times. If times is unspecified, yields the object
forever. If times is negative, behave as if times is 0.<br>
</blockquote>
<br>
documentation:<br>
<blockquote>repeat(object [,times]) -> iterator<br>
<br>
Return an iterator which yields the object for the specified
number of times. If times is unspecified, yields the object
forever. If times is negative, behave as if times is 0.<br>
<br>
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1">
Equivalent to:<br>
<br>
def repeat(object, times=None):<br>
# repeat(10, 3) --> 10 10 10<br>
if times is None:<br>
while True:<br>
yield object<br>
else:<br>
for i in range(times):<br>
yield object<br>
<br>
A common use for repeat is to supply a stream of constant values
to map or zip:<br>
<br>
>>><br>
>>> list(map(pow, range(10), repeat(2)))<br>
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]<br>
<br>
.. note: if "times" is specified using a keyword argument, and
provided with a negative value, repeat yields the object forever.
This is a bug, its use is unsupported, and this behavior may be
removed in a future version of Python.<br>
</blockquote>
<br>
<br>
<i>/arry</i><br>
</body>
</html>