Mattflaschen added a comment.

I think it should be implemented as an infinite generator 
<http://en.literateprograms.org/Fibonacci_numbers_%28Python%29#Generator>.  
Thus, the developer calling Pywikibot should simply be able to iterate as if it 
were an infinite list.  Something like (exact parameters to topics can be 
hashed out later; you may also want to let them choose the number loaded per 
page, as you mentioned, but it should have a sane default):

(Note also there are two orderings, both of which should be supported)

  for topic in board.topics( 'newest' ):

Internally, it would call view-topiclist as many times as necessary, using the 
continuation options (offset/offset-id) to get new pages as needed.

There's the question of what happens if they call board.topics() more than 
once.  I would suggest it just restarts uncached; otherwise, you have to cache 
every topic you've already returned from the generator.

There is a common use case where a bot author may need e.g. the first 100 
topics.  If they just loop through the first 100 once, they can use the 
generator and simply break.  If they need to do so more then once (on the same 
first 100), they could use 
https://docs.python.org/2/library/itertools.html#itertools.islice .  We could 
provide dedicated support for this use case (looping over same first n topics 
multiple times), but I don't think it's necessary.


TASK DETAIL
  https://phabricator.wikimedia.org/T101261

EMAIL PREFERENCES
  https://phabricator.wikimedia.org/settings/panel/emailpreferences/

To: happy5214, Mattflaschen
Cc: Spage, Liuxinyu970226, Aklapper, happy5214, Legoktm, gerritbot, rmoen, 
EBernhardson, NiharikaKohli, Capt_Swing, Qgil, jayvdb, Mattflaschen, Xqt, 
Ricordisamoa, Multichill, Ladsgroup, pywikipedia-bugs



_______________________________________________
pywikibot-bugs mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-bugs

Reply via email to