[ZCM] [ZC] 2326/ 1 Request "LazyCat.__getitem__() called via __repr__() cripples LazyCat.__add__()"

"Collector: Zope Bugs, Features, and Patches ..." <[email protected]> Sun, 20 May 2007 20:26:17 -0400
Newsgroups gmane.comp.web.zope.devel.collector-monitor
Message-ID <[email protected]>
Issue #2326 Update (Request) "LazyCat.__getitem__() called via __repr__() cripples LazyCat.__add__()"
 Status Pending, Catalog/bug medium
To followup, visit:
  http://www.zope.org/Collectors/Zope/2326

==============================================================
= Request - Entry #1 by seanupton on May 20, 2007 8:26 pm

You can add LazyCats together, but only before __repr__() is called or an instance is cast to another sequence type: __getitem__() removes self._seq on line 106 of r40218 in HEAD.  To duplicate:

>>> from Products.ZCatalog.Lazy import LazyCat
>>> lazy1 = LazyCat([ [1,2], ])
>>> lazy1._seq
[[1, 2]]
>>> lazy1 += LazyCat([ [3,4], ])
>>> lazy1._seq
[[1, 2], [3, 4]]
>>> print lazy1 # __repr__ casts to list, calls getitem, removes lazy1._seq
[1, 2, 3, 4]
>>> lazy1._seq #this is bad
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: LazyCat instance has no attribute '_seq'
>>> lazy1 += LazyCat([ [5,6], ]) #this fails because of this bug!
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/home/upton/eg/swhome/lib/python/Products/ZCatalog/Lazy.py", line 43, in __add__
    return LazyCat([self, other])
  File "/home/upton/eg/swhome/lib/python/Products/ZCatalog/Lazy.py", line 68, in __init__
    flattened_seq.extend(s._seq)
AttributeError: LazyCat instance has no attribute '_seq'

==============================================================