generators can't be @collection_default_content
Bug #398050 reported by
Barry Warsaw
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
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.
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.
Changed in lazr.restful: | |
status: | New → Triaged |
importance: | Undecided → Low |
To post a comment you must log in.
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.