Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve SeqIter documentation #90253

Closed
turepalsson mannequin opened this issue Dec 16, 2021 · 5 comments
Closed

Improve SeqIter documentation #90253

turepalsson mannequin opened this issue Dec 16, 2021 · 5 comments
Assignees
Labels
3.10 only security fixes 3.11 only security fixes docs Documentation in the Doc dir

Comments

@turepalsson
Copy link
Mannequin

turepalsson mannequin commented Dec 16, 2021

BPO 46095
Nosy @rhettinger, @merwok, @miss-islington
PRs
  • bpo-46095: Improve SeqIter documentation. #30316
  • [3.10] bpo-46095: Improve SeqIter documentation. (GH-30316) #30330
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/rhettinger'
    closed_at = <Date 2022-01-01.18:38:20.751>
    created_at = <Date 2021-12-16.09:48:01.177>
    labels = ['3.11', '3.10', 'docs']
    title = 'Improve SeqIter documentation'
    updated_at = <Date 2022-01-01.19:12:51.252>
    user = 'https://bugs.python.org/turepalsson'

    bugs.python.org fields:

    activity = <Date 2022-01-01.19:12:51.252>
    actor = 'rhettinger'
    assignee = 'rhettinger'
    closed = True
    closed_date = <Date 2022-01-01.18:38:20.751>
    closer = 'rhettinger'
    components = ['Documentation']
    creation = <Date 2021-12-16.09:48:01.177>
    creator = 'turepalsson'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 46095
    keywords = ['patch']
    message_count = 5.0
    messages = ['408680', '408808', '408832', '409469', '409473']
    nosy_count = 5.0
    nosy_names = ['rhettinger', 'eric.araujo', 'docs@python', 'miss-islington', 'turepalsson']
    pr_nums = ['30316', '30330']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue46095'
    versions = ['Python 3.10', 'Python 3.11']

    @turepalsson
    Copy link
    Mannequin Author

    turepalsson mannequin commented Dec 16, 2021

    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.

    @turepalsson turepalsson mannequin assigned docspython Dec 16, 2021
    @turepalsson turepalsson mannequin added type-feature A feature request or enhancement 3.10 only security fixes docs Documentation in the Doc dir labels Dec 16, 2021
    @turepalsson turepalsson mannequin assigned docspython Dec 16, 2021
    @turepalsson turepalsson mannequin added type-feature A feature request or enhancement 3.10 only security fixes docs Documentation in the Doc dir labels Dec 16, 2021
    @merwok
    Copy link
    Member

    merwok commented Dec 17, 2021

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

    @rhettinger
    Copy link
    Contributor

    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

    @rhettinger rhettinger assigned rhettinger and unassigned docspython Dec 18, 2021
    @rhettinger rhettinger added the 3.11 only security fixes label Dec 18, 2021
    @rhettinger rhettinger changed the title Warning about iterate/modify has unwarranted detail Improve SeqIter documentation Dec 18, 2021
    @rhettinger rhettinger added 3.11 only security fixes and removed type-feature A feature request or enhancement labels Dec 18, 2021
    @rhettinger rhettinger changed the title Warning about iterate/modify has unwarranted detail Improve SeqIter documentation Dec 18, 2021
    @rhettinger rhettinger removed the type-feature A feature request or enhancement label Dec 18, 2021
    @rhettinger
    Copy link
    Contributor

    New changeset a09bc3a by Raymond Hettinger in branch 'main':
    bpo-46095: Improve SeqIter documentation. (GH-30316)
    a09bc3a

    @rhettinger
    Copy link
    Contributor

    New changeset e9783d6 by Miss Islington (bot) in branch '3.10':
    bpo-46095: Improve SeqIter documentation. (GH-30316) (GH-30330)
    e9783d6

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.10 only security fixes 3.11 only security fixes docs Documentation in the Doc dir
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants