I created a collection and iterator class in an External Method for use by my web app. I implmented the iterator protocol introduced by python 2.2, but also included a __getitem__ method to provide the "old" iteration mechanism. For various reasons, the client of my iterator needs to know some information regarding where in the iteration process the iterator is at. I had little trouble making the iterator itself, but I kept getting odd assertion errors and minor defects in the way data was retrieved from my iterator. I managed to track it down to the fact that __getitem__ is called twice with 0 as the index. The sequence of index values looks like : [0, 0, 1, 2, 3, 4, 5, 6, 7, 8] I can work around this anomaly by resetting my iterator every time the index is 0. Is this a bug in zope? (I expect that the bug is in ZTUtils/Iterator.py) I'm using zope 2.5.1, python 2.1.3, debian 3.0. -D -- The way of a fool seems right to him, but a wise man listens to advice. Proverbs 12:15 GnuPG key : http://dman.ddts.net/~dman/public_key.gpg
dman wrote:
Is this a bug in zope? (I expect that the bug is in ZTUtils/Iterator.py)
Even if it's not, it might be worth reporting to: http://collector.zope.org and to zpt@zope.org. cheers, Chris
dman writes:
.... I managed to track it down to the fact that __getitem__ is called twice with 0 as the index. The sequence of index values looks like : [0, 0, 1, 2, 3, 4, 5, 6, 7, 8] I can work around this anomaly by resetting my iterator every time the index is 0.
Is this a bug in zope? (I expect that the bug is in ZTUtils/Iterator.py) I do not call this a bug, because there is not spec that forbids to call an index twice.
Dieter
On Wed, May 08, 2002 at 10:37:12PM +0200, Dieter Maurer wrote: | dman writes: | > .... | > I managed to track it down to the fact that | > __getitem__ is called twice with 0 as the index. The sequence of | > index values looks like : [0, 0, 1, 2, 3, 4, 5, 6, 7, 8] | > I can work around this anomaly by resetting my iterator every time the | > index is 0. | > | > Is this a bug in zope? (I expect that the bug is in ZTUtils/Iterator.py) | | I do not call this a bug, because there is not spec that forbids to | call an index twice. I suppose you may have a point ... the problem lies in python's pre-iterators iteration semantics. The __getitem__ serves as the interface for both a random-access collection and a one-way iterator. I expected tal:repeat to have the same semantics as python's 'for'. At the least it should be defined that tal:repeat only works on random-access containers and doesn't work with one-way iterators. -D -- How great is the love the Father has lavished on us, that we should be called children of God! 1 John 3:1 GnuPG key : http://dman.ddts.net/~dman/public_key.gpg
participants (3)
-
Chris Withers -
Dieter Maurer -
dman