[PEAK] QueryDM's with no query params

Erik Rose psucorp at grinchcentral.com
Fri May 20 22:52:49 EDT 2005

>> and I can't even figure out what it's finding to iterate over. (I 
>> can't find any __iter__() calls or anything.)
> Python will iterate over anything with a __getitem__.

Ah. I'm still learning to find my way around the Python documentation.

> This would be simplest:
>     def __iter__(self):
>         for item in self[0]:
>             yield item

Ah, so that is the best one can do. Thanks. I had done almost the same 
thing, saving a generator, I think...

def __iter__(self):
	return iter(self[0])

...and I stuck it in a ParamlessQueryDM class that I mixed into my 
parameterless QueryDM's. I still wonder why it was iterating forever. 
Maybe that belies a deeper bug someplace; I may take a look when 
schedule permits.

> And perhaps QueryDM should get a default __iter__ that raises 
> NotImplementedError

A good idea, IMO. That would at least save people like me a few 
minutes, if by no other means than the comments above such a stub.

> , and __iter__ can then also be overridden (by DM's that wish to do 
> so) to iterate over all their contents.  This, in conjunction with the 
> 'add' and 'remove' stubs, would move a few steps towards making 
> today's DM's look like tomorrow's "workspaces".

Sounds like a good effort/reward ratio to me. I do want to thank you 
for continuing to answer questions about this existing stuff, even as 
you forge new frontiers in peak.query. :-)


More information about the PEAK mailing list