Skip to content

Incompatible behavior on Python 3.4 vs Python 3.5 #198

@eywalker

Description

@eywalker

It turns out that something that's OK on Python 3.4 may no longer be so in Python 3.5. The following code that modifies the OrderedDict content during the iteration fails on Python 3.5 but works fine on Python 3.4.

from collections import OrderedDict
d = OrderedDict([('a', 'a'), ('b', 'b'), ('c', 'c')])

for v in d.values():
    if v == 'b':
        d.pop(v)

Mechanism similar to the above manipulation is actually used within our DataJoint code, and as a result the code works on Python 3.4, but fails on Python 3.5. This can be verified by the fact that our project code passing on TravisCI Python 3.4 platform fails on Python 3.5.

Given this, I propose that we include Python 3.5 as a target platform to test in addition to Python 3.4 and correct usage like above. Either way, modification of the iterator during the iteration is considered a bad practice with non-obvious consequences!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions