[Bf-python] Proposed BPyAPI Additions.

Emanuel Greisen blender at emanuelgreisen.dk
Sat Dec 16 23:18:49 CET 2006


>
> I'm not sure this is worth it, though.  might be better to just have a
> system that raises an error if you try and call .add or .remove while
> iterating though.

In Java they have the ConcurrentModificationException which in case of 
sets and maps is thrown when accessing an iterator ,which was created 
before a modification, after the modification. This works very well in 
letting the script-author know that his iterator is invalid after a 
modification.

for(Object o : objs)
{
    objs.add(new Object(o));
}

Fails because trying to access the iterator after the call to add will 
detect the concurrent modification. But it will allow things like this:

for(Object o : objs)
{
    if(foo)
    {
       objs.add(new Object(o));
       break;
    }
}

Since you are not accessing the iterator, due to the "break".

./Emanuel



More information about the Bf-python mailing list