classification
Title: Exhausted array iterator should left exhausted
Type: behavior Stage: resolved
Components: Extension Modules Versions: Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: benjamin.peterson, haypo, larry, python-dev, rhettinger, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2016-03-06 16:04 by serhiy.storchaka, last changed 2016-03-31 12:18 by serhiy.storchaka. This issue is now closed.

Files
File name Uploaded Description Edit
exhausted_array_iterator.patch serhiy.storchaka, 2016-03-06 16:04 review
exhausted_array_iterator2.patch serhiy.storchaka, 2016-03-08 09:38 review
Messages (7)
msg261260 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-03-06 16:04
There is general rule that after raising StopIteration the iterator should always raise StopIteration even if new data is added to iterating sequence. Array iterators don't obey this rule.

Proposed patch makes array iterator to left in exhausted state since it achieved. As a side (or may be primary) effect of this change, iterating sequence can be freed just after iterating is finished.

Added tests for other iterators of resizable sequences.

I don't know whether this patch should be applied to maintained releases or only to default branch. Note that array pickling tests broken by this patch were just added. They just expose current (presumably incorrect) behavior.
msg261329 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2016-03-08 06:37
Can you add just one patch to seq_test.py?
msg261338 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-03-08 09:38
Thanks for suggestion Benjamin.

seq_tests.py provides common tests for list, tuple, UserList and deque. This test doesn't work for tuple, since it is not mutable. It doesn't work for deque, since it can't be iterated after changing size. Common test for list and UserList can be moved to list_tests.py. In any case we need separate tests for bytearray, array and general sequence iterator.

I would be happy to not repeat the test, but tests for array and general sequence iterator have not much common with test for list.

Updated patch moves list test to list_tests.py (it now works for UserList) and reuses in for bytearray.
msg261339 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2016-03-08 10:42
I reviewed exhausted_array_iterator2.patch.
msg261342 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-03-08 10:57
Thanks Victor. Answered you comments.
msg261344 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-03-08 11:01
TODO: After resolving issue26494 add similar test for array.
msg262676 - (view) Author: Roundup Robot (python-dev) Date: 2016-03-30 18:11
New changeset 89ba67ee83d6 by Serhiy Storchaka in branch '3.5':
Issue #26492: Added additional tests for exhausted iterators of mutable sequences.
https://hg.python.org/cpython/rev/89ba67ee83d6

New changeset b4ea00d50e7e by Serhiy Storchaka in branch 'default':
Issue #26492: Added additional tests for exhausted iterators of mutable sequences.
https://hg.python.org/cpython/rev/b4ea00d50e7e

New changeset 249ef9d02aa6 by Serhiy Storchaka in branch '2.7':
Issue #26492: Added additional tests for exhausted iterators of mutable sequences.
https://hg.python.org/cpython/rev/249ef9d02aa6

New changeset b6eebe7cf5ae by Serhiy Storchaka in branch 'default':
Issue #26492: Exhausted iterator of array.array now conforms with the behavior
https://hg.python.org/cpython/rev/b6eebe7cf5ae
History
Date User Action Args
2016-03-31 12:18:36serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2016-03-30 18:11:50python-devsetnosy: + python-dev
messages: + msg262676
2016-03-08 11:01:56serhiy.storchakasetmessages: + msg261344
2016-03-08 10:57:36serhiy.storchakasetmessages: + msg261342
2016-03-08 10:42:37hayposetnosy: + haypo
messages: + msg261339
2016-03-08 09:38:41serhiy.storchakasetfiles: + exhausted_array_iterator2.patch

messages: + msg261338
2016-03-08 06:37:01benjamin.petersonsetmessages: + msg261329
2016-03-06 16:04:40serhiy.storchakacreate