jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/808426 )
Change subject: Revert "[bugfix] Respect limit argument with Board.topics()" ......................................................................
Revert "[bugfix] Respect limit argument with Board.topics()"
This reverts commit 4342aeb9e29e4f365d88b6c1a63fca67d1928cdb.
Reason for revert: too many failing tests since this commit
Change-Id: I95714030f7995502c3eaebfbca1d32e90aa894ac --- M pywikibot/flow.py M pywikibot/site/_extensions.py M tests/flow_tests.py 3 files changed, 39 insertions(+), 57 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/flow.py b/pywikibot/flow.py index 8adbb95..71cc206 100644 --- a/pywikibot/flow.py +++ b/pywikibot/flow.py @@ -6,26 +6,29 @@ # import abc import datetime -from typing import Any, Type, Optional, Union +import logging +from typing import Any, Type, Union from urllib.parse import parse_qs, urlparse
import pywikibot from pywikibot.backports import Dict, Iterator, List, Mapping -from pywikibot import config from pywikibot.exceptions import ( LockedPageError, NoPageError, UnknownExtensionError, ) from pywikibot.page import BasePage, PageSourceType, User -from pywikibot.tools import cached, deprecated_args +from pywikibot.tools import cached
+logger = logging.getLogger('pywiki.wiki.flow') + + +# Flow page-like objects (boards and topics) class FlowPage(BasePage, abc.ABC):
"""The base page meta class for the Flow extension.
- Defines Flow page-like object for :class:`Board` and :class:`Topic`. It cannot be instantiated directly. """
@@ -106,29 +109,17 @@ new_params[key] = value return new_params
- @deprecated_args(limit='total') # since 7.4.0 - def topics(self, *, - content_format: str = 'wikitext', - total: Optional[int] = None, + def topics(self, content_format: str = 'wikitext', limit: int = 100, sort_by: str = 'newest', offset: Union[str, datetime.datetime, None] = None, - offset_uuid: str = '', - reverse: bool = False, - include_offset: bool = False, - toc_only: bool = False + offset_uuid: str = '', reverse: bool = False, + include_offset: bool = False, toc_only: bool = False ) -> Iterator['Topic']: """Load this board's topics.
- .. versionchanged:: 7.4 - The *total* parameter was added as a per request limit. - All parameters are keyword only parameters. - .. deprecated:: 7.4 - The *limit* parameter. Use `-step` global option or - `config.step` instead. - :param content_format: The content format to request the data in; must be either 'wikitext', 'html', or 'fixed-html' - :param total: The number of topics to fetch. + :param limit: The number of topics to fetch in each request. :param sort_by: Algorithm to sort topics by; must be either 'newest' or 'updated' :param offset: The timestamp to start at (when sortby is 'updated'). @@ -138,25 +129,17 @@ :param toc_only: Whether to only include information for the TOC. :yield: A generator of this board's topics. """ - maxlimit = min(config.step, 100) if config.step > 0 else 100 - request_limit = min(total, maxlimit) data = self.site.load_topiclist(self, content_format=content_format, - limit=request_limit, sortby=sort_by, + limit=limit, sortby=sort_by, toconly=toc_only, offset=offset, offset_id=offset_uuid, reverse=reverse, include_offset=include_offset) - count = 0 while data['roots']: for root in data['roots']: topic = Topic.from_topiclist_data(self, root, data) yield topic - - count += 1 - if count >= total: - return - - continue_args = self._parse_url(data['links']['pagination']) - data = self.site.load_topiclist(self, **continue_args) + cont_args = self._parse_url(data['links']['pagination']) + data = self.site.load_topiclist(self, **cont_args)
def new_topic(self, title: str, content: str, content_format: str = 'wikitext') -> 'Topic': diff --git a/pywikibot/site/_extensions.py b/pywikibot/site/_extensions.py index d855226..220db27 100644 --- a/pywikibot/site/_extensions.py +++ b/pywikibot/site/_extensions.py @@ -4,11 +4,10 @@ # # Distributed under the terms of the MIT license. # -from typing import Any, Optional, Union +from typing import Optional
import pywikibot from pywikibot.data import api -from pywikibot.backports import Dict from pywikibot.echo import Notification from pywikibot.exceptions import ( APIError, @@ -372,34 +371,39 @@ return data['flow']['view-topiclist']['result']['topiclist']
@need_extension('Flow') - def load_topiclist(self, - page: 'pywikibot.flow.Board', - *, - content_format: str = 'wikitext', - limit: int = 100, - sortby: str = 'newest', - toconly: bool = False, - offset: Union['pywikibot.Timestamp', str, None] = None, - offset_id: Optional[str] = None, - reverse: bool = False, - include_offset: bool = False) -> Dict[str, Any]: + def load_topiclist( + self, + page, + content_format: str = 'wikitext', + limit: int = 100, + sortby: str = 'newest', + toconly: bool = False, + offset=None, + offset_id=None, + reverse: bool = False, + include_offset: bool = False + ): """ Retrieve the topiclist of a Flow board.
- .. versionchanged:: 7.4 - All parameters except *page* are keyword only parameters. - :param page: A Flow board + :type page: Board :param content_format: The content format to request the data in. must be either 'wikitext', 'html', or 'fixed-html' - :param limit: The number of topics to fetch in each single request. + :param limit: The number of topics to fetch in each request. :param sortby: Algorithm to sort topics by ('newest' or 'updated'). :param toconly: Whether to only include information for the TOC. + :type toconly: bool :param offset: The timestamp to start at (when sortby is 'updated'). + :type offset: Timestamp or equivalent str :param offset_id: The topic UUID to start at (when sortby is 'newest'). + :type offset_id: str (in the form of a UUID) :param reverse: Whether to reverse the topic ordering. + :type reverse: bool :param include_offset: Whether to include the offset topic. + :type include_offset: bool :return: A dict representing the board's topiclist. + :rtype: dict """ if offset: offset = pywikibot.Timestamp.fromtimestampformat(offset) diff --git a/tests/flow_tests.py b/tests/flow_tests.py index 3a78317..21575da 100755 --- a/tests/flow_tests.py +++ b/tests/flow_tests.py @@ -8,7 +8,6 @@ import unittest from contextlib import suppress
-from pywikibot import config from pywikibot.exceptions import NoPageError from pywikibot.flow import Board, Post, Topic from tests.aspects import TestCase @@ -142,14 +141,10 @@ def test_topiclist(self): """Test loading of topiclist.""" board = self._page - total = 7 - for step in (-1, 5, 100): - with self.subTest(step=step): - config.step = step - for i, _ in enumerate(board.topics(total=total), start=1): - if i > total: - break - self.assertEqual(i, total) + for i, _ in enumerate(board.topics(limit=7), start=1): + if i == 10: + break + self.assertEqual(i, 10)
class TestFlowFactoryErrors(TestCase):
pywikibot-commits@lists.wikimedia.org