You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
In itertools.chain.from_iterable() there is no cls argument #62501
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:
assignee='https://github.com/rhettinger'closed_at=<Date2013-09-09.06:57:17.906>created_at=<Date2013-06-25.18:58:43.184>labels= ['type-feature', 'docs']
title='In itertools.chain.from_iterable() there is no cls argument'updated_at=<Date2013-09-09.06:57:17.905>user='https://github.com/py-user'
>>> classA:
... @classmethod
... deffrom_iterable(iterables):
... for it in iterables:
... for element in it:
... yield element
...
>>> A.from_iterable(['ABC', 'DEF'])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: from_iterable() takes 1 positional argument but 2 were given
>>>
It is implemented as a classmethod, but the "equivalent" code doesn't need to be part of the class all. I'm not sure what should be done here (say @staticmethod? Leave the decorator off?). We should probably see what Raymond thinks. I lean toward the latter, that's the way it is in the python2 docs, and it doesn't seem to have caused any confusion.
The 2.7 doc says 'Roughly equivalent to' rather than 'Equivalent to'.
The undecorated Python version of from_iterable actually works as an attribute of the Python version of chain: chain.from_iterable = from_iterable. I would just remove the decorator. The entire itertools doc exploits that fact that generator functions are analogous to classes, but it does not work to mix the two in the way that the 3.x chain entry does.
My counter proposal bpo-18752 is that chain.from_iterable become a deprecated alias for a new function, chain_iterable. With '@classmethod' removed, the current Python equivalent would work for chain_iterable.
Activity
py-user commentedon Jun 25, 2013
http://docs.python.org/2/library/itertools.html#itertools.chain.from_iterable
py-user commentedon Jun 25, 2013
http://docs.python.org/3/library/itertools.html#itertools.chain.from_iterable
bitdancer commentedon Jun 25, 2013
It is implemented as a classmethod, but the "equivalent" code doesn't need to be part of the class all. I'm not sure what should be done here (say @staticmethod? Leave the decorator off?). We should probably see what Raymond thinks. I lean toward the latter, that's the way it is in the python2 docs, and it doesn't seem to have caused any confusion.
terryjreedy commentedon Jun 28, 2013
The 2.7 doc says 'Roughly equivalent to' rather than 'Equivalent to'.
The undecorated Python version of from_iterable actually works as an attribute of the Python version of chain: chain.from_iterable = from_iterable. I would just remove the decorator. The entire itertools doc exploits that fact that generator functions are analogous to classes, but it does not work to mix the two in the way that the 3.x chain entry does.
serhiy-storchaka commentedon Jun 28, 2013
Perhaps it should be staticmethod, not classmethod.
serhiy-storchaka commentedon Aug 6, 2013
It should be a classmethod.
The patch LGTM.
ezio-melotti commentedon Aug 8, 2013
+1
py-user commentedon Aug 8, 2013
it should be B
py-user commentedon Aug 9, 2013
changed iter(arg) to *arg
terryjreedy commentedon Aug 15, 2013
My counter proposal bpo-18752 is that chain.from_iterable become a deprecated alias for a new function, chain_iterable. With '@classmethod' removed, the current Python equivalent would work for chain_iterable.
python-dev commentedon Sep 9, 2013
New changeset 29fa1f418796 by Raymond Hettinger in branch '3.3':
bpo-18301: The classmethod decorator didn't fit well with the rough-equivalent example code.
http://hg.python.org/cpython/rev/29fa1f418796