python / cpython

The Python programming language
https://www.python.org
Other
63.15k stars 30.24k forks source link

Documentation for itertools.chain.from_iterable is incorrect #56699

Closed 0b383f79-79e4-4275-9d9c-e5a1dad72532 closed 13 years ago

0b383f79-79e4-4275-9d9c-e5a1dad72532 commented 13 years ago
BPO 12490

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields: ```python assignee = None closed_at = created_at = labels = ['invalid', 'docs'] title = 'Documentation for itertools.chain.from_iterable is incorrect' updated_at = user = 'https://bugs.python.org/RodolphoEckhardt' ``` bugs.python.org fields: ```python activity = actor = 'RodolphoEckhardt' assignee = 'docs@python' closed = True closed_date = closer = 'RodolphoEckhardt' components = ['Documentation'] creation = creator = 'RodolphoEckhardt' dependencies = [] files = [] hgrepos = [] issue_num = 12490 keywords = [] message_count = 2.0 messages = ['139802', '139804'] nosy_count = 1.0 nosy_names = ['RodolphoEckhardt'] pr_nums = [] priority = 'normal' resolution = 'not a bug' stage = None status = 'closed' superseder = None type = None url = 'https://bugs.python.org/issue12490' versions = ['Python 2.7', 'Python 3.2'] ```

0b383f79-79e4-4275-9d9c-e5a1dad72532 commented 13 years ago

The documentation at http://docs.python.org/py3k/library/itertools.html#itertools.chain and http://docs.python.org/library/itertools.html#itertools.chain is inconsistent.

At the definition of the class it states that itertools.chain.from_iterable can receive one iterable "Gets chained inputs from a single iterable argument that is evaluated lazily.", but then it contradicts itself by using the following example:

@classmethod
def from_iterable(iterables):
    # chain.from_iterable(['ABC', 'DEF']) --> A B C D E F
    for it in iterables:
        for element in it:
            yield element

This example could lead the reader to believe this alternative constructor can receive multiple iterable objects, when in fact it can receive only one.

0b383f79-79e4-4275-9d9c-e5a1dad72532 commented 13 years ago

My mistake reading the documentation. Sorry, closing this issue.