Skip to content

for-each on list aborts earlier than expected #64022

Closed

Description

@cost6
mannequin
BPO 19823

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 = None
closed_at = <Date 2013-11-28.15:21:43.492>
created_at = <Date 2013-11-28.14:03:18.228>
labels = ['interpreter-core', 'type-bug']
title = 'for-each on list aborts earlier than expected'
updated_at = <Date 2013-11-28.15:21:43.491>
user = 'https://bugs.python.org/cost6'

bugs.python.org fields:

activity = <Date 2013-11-28.15:21:43.491>
actor = 'cost6'
assignee = 'none'
closed = True
closed_date = <Date 2013-11-28.15:21:43.492>
closer = 'cost6'
components = ['Interpreter Core']
creation = <Date 2013-11-28.14:03:18.228>
creator = 'cost6'
dependencies = []
files = []
hgrepos = []
issue_num = 19823
keywords = []
message_count = 3.0
messages = ['204653', '204669', '204670']
nosy_count = 2.0
nosy_names = ['mrabarnett', 'cost6']
pr_nums = []
priority = 'normal'
resolution = 'works for me'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue19823'
versions = ['Python 3.3']

Activity

  1. cost6 commented on Nov 28, 2013

    cost6mannequin
    MannequinAuthor

    for-each does not iterate over all entries of collection, if one removes elements during the iteration.

    Example (misbehaving) code:

    def keepByValue(self, key=None, value=[]):
        for row in self.flows:
            if not row[key] in value:
                flows.remove(row)
  2. added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)
    type-bugAn unexpected behavior, bug, or error
    on Nov 28, 2013
  3. mrabarnett commented on Nov 28, 2013

    mrabarnettmannequin
    Mannequin

    This issue is best posted to python-list and only posted here if it's agreed that it's a bug.

    Anyway:

    1. You have "self.flows" and "flows", but haven't said what they are.

    2. It's recommended that you don't modify a collection while iterating over it, but, instead, build a new collection and then the old one with the new one.

  4. cost6 commented on Nov 28, 2013

    cost6mannequin
    MannequinAuthor

    Sorry for that, i will move it to python-list.

  5. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions