[Python-Dev] Negative times behaviour in itertools.repeat for Python maintenance releases (2.7, 3.3 and maybe 3.4) (original) (raw)
Larry Hastings larry at hastings.org
Tue Jan 28 07:06:57 CET 2014
- Previous message: [Python-Dev] Negative times behaviour in itertools.repeat for Python maintenance releases (2.7, 3.3 and maybe 3.4)
- Next message: [Python-Dev] Negative times behaviour in itertools.repeat for Python maintenance releases (2.7, 3.3 and maybe 3.4)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 01/27/2014 06:26 PM, Vajrasky Kok wrote:
So I believe the doc fix is required then.
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.
If I were writing it, it might well come out like this:
docstring:
repeat(object [,times]) -> iterator
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.
documentation:
repeat(object [,times]) -> iterator
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.
Equivalent to:
def repeat(object, times=None):
# repeat(10, 3) --> 10 10 10
if times is None:
while True:
yield object
else:
for i in range(times):
yield object
A common use for repeat is to supply a stream of constant values to
map or zip:
>>>
>>> list(map(pow, range(10), repeat(2)))
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
.. 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.
//arry/ -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20140127/5c6b6b5c/attachment.html>
- Previous message: [Python-Dev] Negative times behaviour in itertools.repeat for Python maintenance releases (2.7, 3.3 and maybe 3.4)
- Next message: [Python-Dev] Negative times behaviour in itertools.repeat for Python maintenance releases (2.7, 3.3 and maybe 3.4)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]