Terry J. Reedy <tjre...@udel.edu> added the comment:

Title corrected. Non-iterator iterables are usually easy to copy.
I think this is in the category of "don't do that" ;-)

I believe the idea of making iterators copyable has been rejected on one of the 
lists because it is probably not possible in general.
Tee consumes indefinite and unbounded space. Its use should be explicit. If a 
function needs to iterate more than once with an input iterable, it should 
explicitly do list(iterator) for iterator inputs.
See Raymond's comments, such as msg156720 in #14288.

So I suspect that raising an error for copy.copy(iter([])) is correct. The 
error message amounts to saying make a new instance with the class constructor. 
That is usually correct when copy is not possible, but not in this case. 
ListIterator.__new__ is the inherited object.__new__. It appears that 
ListIterators can only be constructed by list.__iter__. But I doubt that the 
code that raises the error message can know that.
But perhaps the error message can be improved anyway.

----------
nosy: +alexandre.vassalotti, rhettinger, terry.reedy
stage:  -> needs patch
title: Strange Exception from copying an iterable -> Strange Exception from 
copying an iterator

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue14350>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to