jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/961414 )
Change subject: [cleanup] Remove rawcontinue code parts ......................................................................
[cleanup] Remove rawcontinue code parts
Bug: T343204 Change-Id: I6c4275cb501cff3fece64738e75e3b0772049a79 --- M tests/site_generators_tests.py M pywikibot/data/api/_requests.py M pywikibot/data/api/_generators.py 3 files changed, 30 insertions(+), 25 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/data/api/_generators.py b/pywikibot/data/api/_generators.py index e483ef3..9e25f52 100644 --- a/pywikibot/data/api/_generators.py +++ b/pywikibot/data/api/_generators.py @@ -12,12 +12,14 @@ # from abc import ABC, abstractmethod from contextlib import suppress -from typing import Union +from typing import Optional, Union from warnings import warn
import pywikibot from pywikibot import config +from pywikibot.backports import List from pywikibot.exceptions import Error, InvalidTitleError, UnsupportedPageError +from pywikibot.tools import deprecated from pywikibot.tools.collections import GeneratorWrapper
@@ -102,6 +104,7 @@ self.limit_name = limit_name self.data_name = data_name
+ self.query_increment: Optional[int] if config.step > 0: self.query_increment = config.step else: @@ -213,12 +216,10 @@ _namespaces = None
def __init__(self, **kwargs) -> None: - """ - Initialize a QueryGenerator object. + """Initialize a QueryGenerator object.
kwargs are used to create a Request object; see that object's documentation for values. 'action'='query' is assumed. - """ if not hasattr(self, 'site'): kwargs = self._clean_kwargs(kwargs) # hasn't been called yet @@ -279,6 +280,7 @@ else: self.request[prefix + 'limit'] = int(param['max'])
+ self.api_limit: Optional[int] if config.step > 0: self.api_limit = config.step else: @@ -300,17 +302,14 @@ else: self.resultkey = self.modules[0]
- # usually the (query-)continue key is the same as the querymodule, - # but not always - # API can return more than one query-continue key, if multiple - # properties are requested by the query, e.g. - # "query-continue":{ - # "langlinks":{"llcontinue":"12188973|pt"}, - # "templates":{"tlcontinue":"310820|828|Namespace_detect"}} - # self.continuekey is a list - self.continuekey = self.modules self._add_slots()
+ @property + @deprecated(since='8.4.0') + def continuekey(self) -> List[str]: + """Return deprecated continuekey which is self.modules.""" + return self.modules + def _add_slots(self) -> None: """Add slots to params if the site supports multi-content revisions.
@@ -566,12 +565,14 @@ continue
yield result - if isinstance(item, dict) and set(self.continuekey) & set(item): + + modules_item_intersection = set(self.modules) & set(item) + if isinstance(item, dict) and modules_item_intersection: # if we need to count elements contained in items in # self.data["query"]["pages"], we want to count - # item[self.continuekey] (e.g. 'revisions') and not + # item[self.modules] (e.g. 'revisions') and not # self.resultkey (i.e. 'pages') - for key in set(self.continuekey) & set(item): + for key in modules_item_intersection: self._count += len(item[key]) # otherwise we proceed as usual else: diff --git a/pywikibot/data/api/_requests.py b/pywikibot/data/api/_requests.py index e13bd6f..e9b9bd7 100644 --- a/pywikibot/data/api/_requests.py +++ b/pywikibot/data/api/_requests.py @@ -221,7 +221,7 @@ parameters = kwargs elif parameters is self._PARAM_DEFAULT: parameters = {} - self._params = {} + self._params: Dict[str, Any] = {} if 'action' not in parameters: raise ValueError("'action' specification missing from Request.") self.action = parameters['action'] @@ -432,12 +432,6 @@ and self.site.has_extension('ProofreadPage'): prop = set(self['prop'] + ['proofread']) self['prop'] = sorted(prop) - # When neither 'continue' nor 'rawcontinue' is present we add a - # dummy rawcontinue parameter except for 'tokens' (T284577) and - # 'siteinfo' (T343204) - if ('tokens' not in meta and 'siteinfo' not in meta - and 'continue' not in self._params): - self._params.setdefault('rawcontinue', [''])
elif self.action == 'help': self['wrap'] = '' diff --git a/tests/site_generators_tests.py b/tests/site_generators_tests.py index a2513b3..ec63ae4 100755 --- a/tests/site_generators_tests.py +++ b/tests/site_generators_tests.py @@ -1694,8 +1694,8 @@ self.mysite.loadrevisions(self.mainpage, revids=130000)
- def test_loadrevisions_querycontinue(self): - """Test the site.loadrevisions() method with query-continue.""" + def test_loadrevisions_continue(self): + """Test the site.loadrevisions() method with continue.""" self.mysite.loadrevisions(self.mainpage, step=5, total=12) self.assertLength(self.mainpage._revisions, 12)
pywikibot-commits@lists.wikimedia.org