2008/8/20 Jerome Laheurte <[EMAIL PROTECTED]>:
>
> Hi, Frank. I found a bug and I'm at loss as to how to fix it; I see
> several solutions but they may have other impacts...
>
> The bug: Start with an empty file, create a category, then a
> subcategory, then a task. Edit the parent category and click OK. Edit
> the task. The result:
>
>   File
> "/home/jla/WinHome/dev/fraca7/taskcoach-trunk/taskcoachlib/gui/dialog/editor.py",
> line 531, in getCategoryWithIndex
>     category = children[i]
> IndexError: list index out of range
>
> After some digging, I found out that when the category's state is
> saved, patterns.Composite makes a copy of the children. Thus, when the
> edit is undone, the category's children are replaced with copies. But
> the global list of categories keeps the old versions.

I'm not sure your analysis is correct. patterns.Composite does not
copy the children, it only copies the list containing the children:

class Composite(object):
    ...
    def __getstate__(self):
        return dict(children=self.__children[:], parent=self.__parent)

    def __setstate__(self, state):
        self.__parent = state['parent']
        self.__children = state['children']


Copying a list this way (l[:]) creates a shallow copy; it's a new
list, but it contains the same objects. To illustrate:
>>> l = [[]]
>>> l
[[]]
>>> k = l[:]
>>> k
[[]]
>>> l[0].append(1)
>>> l
[[1]]
>>> k
[[1]]

Cheers, Frank

Reply via email to