]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Make the from_iterable() recipe more usable.
authorRaymond Hettinger <python@rcn.com>
Fri, 28 Dec 2012 08:03:30 +0000 (00:03 -0800)
committerRaymond Hettinger <python@rcn.com>
Fri, 28 Dec 2012 08:03:30 +0000 (00:03 -0800)
The code isn't exactly equivalent because a classmethod would
only make sense inside a chain class, and it would need "cls"
as a first argument, and it would need to return an instance
of "chain" rather than a generator.

The updated example drops the @classmethod decorator so that
it can be used standalone:  list(from_iterable(['abc', 'def']))
This should be communicate what from_iterable does.

Doc/library/itertools.rst

index 8bb9e3672a45983fc8537ff6efbafc50291a9c2d..a7f0058b4cd157735536bc2bfff19c42c17179c0 100644 (file)
@@ -106,9 +106,8 @@ loops that truncate the stream.
 .. classmethod:: chain.from_iterable(iterable)
 
    Alternate constructor for :func:`chain`.  Gets chained inputs from a
-   single iterable argument that is evaluated lazily.  Equivalent to::
+   single iterable argument that is evaluated lazily.  Roughly equivalent to::
 
-      @classmethod
       def from_iterable(iterables):
           # chain.from_iterable(['ABC', 'DEF']) --> A B C D E F
           for it in iterables: