[issue46095] Warning about iterate/modify has unwarranted detail

2021-12-17 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

I think this note can be removed.  The tutorial now has coverage of mutating 
while iterating.  That is the correct place for discussion of looping 
techniques.

The part about the "internal counter" needs to be rewritten and moved to 
stdtypes.rst section on Sequence types.  Here is a first draft:

"Forward and reversed iterators over sequences access values using an index.  
That index will continue to march forward (or backward) even if the underlying 
sequence is mutated.  The iterator terminates only when an IndexError or 
StopIteration is encountered (or when the index drops below zero)."

Sequence iterators are roughly equivalent to:

def seqiter(seq):
i = 0
while True:
try:
yield seq[i]
except (IndexError, StopIteration):
break
i += 1

--
assignee: docs@python -> rhettinger
nosy: +rhettinger

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46095] Warning about iterate/modify has unwarranted detail

2021-12-17 Thread Éric Araujo

Éric Araujo  added the comment:

The note does say it’s about mutable sequences like lists.

--
nosy: +eric.araujo

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46095] Warning about iterate/modify has unwarranted detail

2021-12-16 Thread Ture Pålsson

New submission from Ture Pålsson :

The language reference about the 'for' statement 
(https://docs.python.org/3/reference/compound_stmts.html#the-for-statement) has 
a "Note" box that states that the for statement uses an "internal counter" 
which is "incremented", and goes into detail about what happens when 
modifications happen before or after the current loop position. Surely this 
depends on the underlying iterator? For example, with a balanced tree an insert 
or a delete could completely re-jigger the tree with hard-to-predict results on 
an iterator.

--
assignee: docs@python
components: Documentation
messages: 408680
nosy: docs@python, turepalsson
priority: normal
severity: normal
status: open
title: Warning about iterate/modify has unwarranted detail
type: enhancement
versions: Python 3.10

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com