This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2013年06月25日 18:58 by py.user, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| issue18301.diff | py.user, 2013年06月25日 18:58 | review | ||
| Messages (11) | |||
|---|---|---|---|
| msg191874 - (view) | Author: py.user (py.user) * | Date: 2013年06月25日 18:58 | |
http://docs.python.org/2/library/itertools.html#itertools.chain.from_iterable >>> class A: ... @classmethod ... def from_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 >>> |
|||
| msg191875 - (view) | Author: py.user (py.user) * | Date: 2013年06月25日 18:59 | |
http://docs.python.org/3/library/itertools.html#itertools.chain.from_iterable |
|||
| msg191884 - (view) | Author: R. David Murray (r.david.murray) * (Python committer) | Date: 2013年06月25日 20:35 | |
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. |
|||
| msg192009 - (view) | Author: Terry J. Reedy (terry.reedy) * (Python committer) | Date: 2013年06月28日 18:53 | |
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. |
|||
| msg192015 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2013年06月28日 19:52 | |
Perhaps it should be staticmethod, not classmethod. |
|||
| msg194535 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2013年08月06日 12:11 | |
It should be a classmethod. >>> import itertools >>> class C(itertools.chain): pass ... >>> type(C.from_iterable(['ab', 'cd'])) <class '__main__.C'> The patch LGTM. |
|||
| msg194668 - (view) | Author: Ezio Melotti (ezio.melotti) * (Python committer) | Date: 2013年08月08日 12:56 | |
> I would just remove the decorator. +1 |
|||
| msg194701 - (view) | Author: py.user (py.user) * | Date: 2013年08月08日 17:45 | |
>>> import itertools
>>>
>>> class A(itertools.chain):
... def from_iter(arg):
... return A(iter(arg))
...
>>> class B(A):
... pass
...
>>> B('a', 'b')
<__main__.B object at 0x7f40116d7730>
>>> B.from_iter(['a', 'b'])
<__main__.A object at 0x7f40116d7780>
>>>
it should be B
|
|||
| msg194712 - (view) | Author: py.user (py.user) * | Date: 2013年08月09日 01:13 | |
changed iter(arg) to *arg
>>> import itertools
>>>
>>> class A(itertools.chain):
... @classmethod
... def from_iter(cls, arg):
... return cls(*arg)
...
>>> class B(A):
... pass
...
>>> B('ab', 'cd')
<__main__.B object at 0x7fc280e93cd0>
>>> b = B.from_iter(['ab', 'cd'])
>>> b
<__main__.B object at 0x7fc280e93d20>
>>> next(b)
'a'
>>> next(b)
'b'
>>> next(b)
'c'
>>> next(b)
'd'
>>> next(b)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
StopIteration
>>>
|
|||
| msg195291 - (view) | Author: Terry J. Reedy (terry.reedy) * (Python committer) | Date: 2013年08月15日 21:08 | |
My counter proposal #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. |
|||
| msg197352 - (view) | Author: Roundup Robot (python-dev) (Python triager) | Date: 2013年09月09日 06:55 | |
New changeset 29fa1f418796 by Raymond Hettinger in branch '3.3': Issue 18301: The classmethod decorator didn't fit well with the rough-equivalent example code. http://hg.python.org/cpython/rev/29fa1f418796 |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:47 | admin | set | github: 62501 |
| 2013年09月09日 06:57:17 | rhettinger | set | status: open -> closed resolution: fixed |
| 2013年09月09日 06:55:43 | python-dev | set | nosy:
+ python-dev messages: + msg197352 |
| 2013年08月15日 21:08:58 | terry.reedy | set | messages: + msg195291 |
| 2013年08月09日 01:13:57 | py.user | set | messages: + msg194712 |
| 2013年08月08日 17:45:26 | py.user | set | messages: + msg194701 |
| 2013年08月08日 12:56:24 | ezio.melotti | set | nosy:
+ ezio.melotti messages: + msg194668 |
| 2013年08月06日 12:17:06 | serhiy.storchaka | set | assignee: serhiy.storchaka -> rhettinger |
| 2013年08月06日 12:11:33 | serhiy.storchaka | set | assignee: docs@python -> serhiy.storchaka messages: + msg194535 stage: commit review |
| 2013年06月28日 19:52:06 | serhiy.storchaka | set | nosy:
+ serhiy.storchaka messages: + msg192015 |
| 2013年06月28日 18:53:53 | terry.reedy | set | nosy:
+ terry.reedy messages: + msg192009 |
| 2013年06月25日 20:35:31 | r.david.murray | set | nosy:
+ rhettinger, r.david.murray messages: + msg191884 |
| 2013年06月25日 18:59:22 | py.user | set | messages: + msg191875 |
| 2013年06月25日 18:58:43 | py.user | create | |