generators can't be @collection_default_content

Bug #398050 reported by Barry Warsaw
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
lazr.restful
Triaged
Low
Unassigned

Bug Description

If you define a function like this:

(in the interface):

    @collection_default_content()
    def __iter__():
        """Iterate over all mailing lists."""

(in the content object):

    def __iter__(self):
        """See `IListManager`."""
        for mailing_list in self.mailing_lists:
            yield mailing_list

You get the following error:

TypeError: ('Could not adapt', <generator object __iter__ at 0x1efab70>, <InterfaceClass zope.interface.common.sequence.IFiniteSequence>)

which makes sense, because you don't know if a generator is a finite sequence. Still, I think it would be nice if generators could somehow be supported, as most of them /are/ finite.

Revision history for this message
Leonard Richardson (leonardr) wrote :

I've run into a similar problem. That cast is happening because we're trying to find the length of the sequence. I believe I can change lazr.batchnavigator to support batching objects with no __len__, at the expense of performance.

Changed in lazr.restful:
status: New → Triaged
importance: Undecided → Low
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.