Python target bug?

I don’t know if this is necessarily a bug, and am not familiar with the development status of the Python target, but I found a difference in behavior between Python and other targets that I’ve tested.

It’s really simple to reproduce, and gives you the runtime error:

RuntimeError: dictionary changed size during iteration

All you have to do is modify a map while iterating over the keys like this:

var map = [
    "key_a" => "val_a",
    "key_b" => "val_b"
];

for(key in map.keys()){
    map.set("key_c", "val_c");
    Sys.println(key + " => " + map.get(key));
}

That code builds and runs just fine on the following targets (the only ones I’ve tested):

  • neko
  • cpp
  • java
  • php
  • lua

but throws the runtime error on Python.

It’s an easy fix, but it seems to me like this is something the Python target should account for to keep the behavior consistent. (although I think the Python target’s behavior is better)