New submission from Michael Seifert:

When using `copy.copy` to copy an `itertools.chain` instance the results can be 
weird. For example

>>> from itertools import chain
>>> from copy import copy
>>> a = chain([1,2,3], [4,5,6])
>>> b = copy(a)
>>> next(a)  # looks okay
1
>>> next(b)  # jumps to the second iterable, not okay?
4
>>> tuple(a)
(2, 3)
>>> tuple(b)
(5, 6)

I don't really want to "copy.copy" such an iterator (I would either use `a, b = 
itertools.tee(a, 2)` or `b = a` depending on the use-case). This just came up 
because I investigated how pythons iterators behave when copied, deepcopied or 
pickled because I want to make the iterators in my extension module behave 
similarly.

----------
components: Library (Lib)
messages: 290106
nosy: MSeifert
priority: normal
severity: normal
status: open
title: itertools.chain behaves strangly when copied with copy.copy
type: behavior
versions: Python 3.5, Python 3.6

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

Reply via email to