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/
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to