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

for-each on list aborts earlier than expected #64022

Closed
cost6 mannequin opened this issue Nov 28, 2013 · 3 comments
Closed

for-each on list aborts earlier than expected #64022

cost6 mannequin opened this issue Nov 28, 2013 · 3 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@cost6
Copy link
Mannequin

cost6 mannequin commented Nov 28, 2013

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']

@cost6
Copy link
Mannequin Author

cost6 mannequin commented Nov 28, 2013

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)

@cost6 cost6 mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Nov 28, 2013
@mrabarnett
Copy link
Mannequin

mrabarnett mannequin commented Nov 28, 2013

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.

@cost6
Copy link
Mannequin Author

cost6 mannequin commented Nov 28, 2013

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

@cost6 cost6 mannequin closed this as completed Nov 28, 2013
@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
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

0 participants