2008/8/21 Jerome Laheurte <[EMAIL PROTECTED]>:
> Actually, I ran trunk for half a day by replacing the
>
> children=[child.copy() for child in self.__children]
>
> with
>
> children=[self.__children[:]]

Without problems I assume, since you are not mentioning any problems?

> in Composite.__getstate__. I dind't realize that the copy stuff
> appeared in trunk. But I'm not sure this fix is right, after all there
> is probably a reason why you changed the shallow copy for a deep one
> in trunk ? This seems to be part of the 'domain objects may have any
> other domain object as children' change.

I'm not entirely sure, but I may have been trying to have copy() use
__getstate__() because of the duplication between __getstate__() and
copy(). I must have decided that that wasn't really possible but not
changed things back again in good order.

I may have seen this (example from patterns.Composite):
   def copy(self, *args, **kwargs):
        kwargs['parent'] = self.parent()
        kwargs['children'] = [child.copy() for child in self.children()]
        return self.__class__(*args, **kwargs)

and thought to myself: hey, I can use __getstate__ to get the
necessary information and then simply have copy look like this
    def copy(self):
        return self.__class__(**self.__getstate__())

Actually, this is what currently happens in domain.base.Object:
    def copy(self):
        state = self.__getstate__()
        del state['id'] # Don't copy the id
        return self.__class__(**state)

But that only works because all base.Object attributes are immutable!

So, I guess we need to make some decisions on how state manipulation
and copying should work (a protocol so to say :-). How about adding a
boolean parameter to __getstate__ called 'deepcopy' that returns a
deep copy of the state if True and a shallow copy otherwise, and then
simply call the method from base.Object.copy?

Cheers, Frank

Reply via email to