[New-bugs-announce] [issue29420] Python 3.6 change in dict iteration when inserting keys

Matthew Brett report at bugs.python.org
Thu Feb 2 09:10:45 EST 2017


New submission from Matthew Brett:

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:

d = {'foo': 1}
for key in d:
   print(key)
   d.pop(key)
   d[key] = 1

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 https://github.com/nipy/nipy/issues/420

----------
messages: 286794
nosy: matthew.brett
priority: normal
severity: normal
status: open
title: Python 3.6 change in dict iteration when inserting keys
type: behavior
versions: Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29420>
_______________________________________


More information about the New-bugs-announce mailing list