[Zope-dev] Zope 2.3.1b1, strange things when ConflictError.
Steve Alexander
steve@cat-box.net
Sun, 25 Feb 2001 23:00:30 +0000
Erik,
You're returning a mutable object from methodB. You should either return
an immutable object (such as a tuple or a string), or return a *copy* of
your mutable object.
some_list.reverse() reverses the list in-place. That's why you're seeing
the strange reversal results you report.
The easiest way to achieve this is to change methodA as below:
>
> def methodA(self):
> "doc string"
> objects = self.methodB(self)
> objects.reverse()
>
> attrib = ''
>
> for object in objects:
> attrib = attrib + 'some html'
>
> return attrib
def methodA(self):
"doc string"
objects = self.methodB(self)[:]
objects.reverse()
Here, you're making a copy of what methodB returns, before doing stuff to it.
Otherwise, you can re-reverse what methodB returns using try: finally: in methodA.
If methodB is called by anything else, as methodB is recursive, you should either make it non-recursive, or access it via a methodC:
def methodC(self, object):
return self.methodB(object)[:]
--
Steve Alexander
Software Engineer
Cat-Box limited
http://www.cat-box.net