Python 3.6 change in dict iteration when inserting keys #73606
Copy link
Copy link
Closed
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
| BPO | 29420 |
|---|---|
| Nosy | @bitdancer |
| Superseder |
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 2017-02-02.14:38:17.926>
created_at = <Date 2017-02-02.14:10:45.449>
labels = ['type-bug']
title = 'Python 3.6 change in dict iteration when inserting keys'
updated_at = <Date 2017-02-02.15:23:38.378>
user = 'https://bugs.python.org/matthewbrett'bugs.python.org fields:
activity = <Date 2017-02-02.15:23:38.378>
actor = 'matthew.brett'
assignee = 'none'
closed = True
closed_date = <Date 2017-02-02.14:38:17.926>
closer = 'r.david.murray'
components = []
creation = <Date 2017-02-02.14:10:45.449>
creator = 'matthew.brett'
dependencies = []
files = []
hgrepos = []
issue_num = 29420
keywords = []
message_count = 3.0
messages = ['286794', '286797', '286804']
nosy_count = 2.0
nosy_names = ['r.david.murray', 'matthew.brett']
pr_nums = []
priority = 'normal'
resolution = 'duplicate'
stage = 'resolved'
status = 'closed'
superseder = '19332'
type = 'behavior'
url = 'https://bugs.python.org/issue29420'
versions = ['Python 3.6']Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Activity
MatthewBrett commentedon Feb 2, 2017
The behavior of dict iteration has changed in Python 3.6, in that inserting keys during iteration has a different and unpredictable affect. For this code:
Python 3.5 prints a single 'foo' (one pass through the loop). Python 3.6 generates five lines of 'foo' (five passes through the loop). Of course this code is pathological, but I found this behavior from a bug in code where the pathology was a lot less obvious - see nipy/nipy#420
bitdancer commentedon Feb 2, 2017
This "bug" has always existed, its just that its manifestation has changed. See bpo-19332 for background.
MatthewBrett commentedon Feb 2, 2017
To clarify from comments on bpo-19332:
"""
"""
The change in Python 3.6 is just a different undefined behavior.