jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/657988 )
Change subject: [6.0] drop support for mw 1.19-1.22 in data/api.py ......................................................................
[6.0] drop support for mw 1.19-1.22 in data/api.py
- also add typing hints - raise a TypeError if mime is given as boolean; this type is deprecated for 3 months - remove dry_api_tests.MimeTests because Request mime parameter's value is no longer changed but a TypeError is raised
Bug: T268979 Change-Id: Ieecf9fda098ed30dff350a952149735575d9b1b1 --- M pywikibot/data/api.py M tests/dry_api_tests.py 2 files changed, 23 insertions(+), 69 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py index bde7b4f..b12553e 100644 --- a/pywikibot/data/api.py +++ b/pywikibot/data/api.py @@ -37,11 +37,7 @@ ) from pywikibot.family import SubdomainFamily from pywikibot.login import LoginStatus -from pywikibot.tools import ( - issue_deprecation_warning, - itergroup, - PYTHON_VERSION, -) +from pywikibot.tools import itergroup, PYTHON_VERSION from pywikibot.tools.formatter import color_format
@@ -973,8 +969,12 @@ # To make sure the default value of 'parameters' can be identified. _PARAM_DEFAULT = object()
- def __init__(self, site=None, mime=None, throttle=True, - max_retries=None, retry_wait=None, use_get=None, + def __init__(self, site=None, + mime: Optional[dict] = None, + throttle: bool = True, + max_retries: Optional[int] = None, + retry_wait: Optional[int] = None, + use_get: Optional[bool] = None, parameters=_PARAM_DEFAULT, **kwargs): """ Create a new Request instance with the given parameters. @@ -1006,14 +1006,13 @@ None). Parameters which should only be transferred via mime mode are defined via this parameter (even an empty dict means mime shall be used). - @type mime: None or dict - @param max_retries: (optional) Maximum number of times to retry after + @param max_retries: Maximum number of times to retry after errors, defaults to config.max_retries. - @param retry_wait: (optional) Minimum time in seconds to wait after an + @param retry_wait: Minimum time in seconds to wait after an error, defaults to config.retry_wait seconds (doubles each retry until config.retry_max seconds is reached). - @param use_get: (optional) Use HTTP GET request if possible. If False - it uses a POST request. If None, it'll try to determine via + @param use_get: Use HTTP GET request if possible. If False it + uses a POST request. If None, it'll try to determine via action=paraminfo if the action requires a POST. @param parameters: The parameters used for the request to the API. @type parameters: dict @@ -1025,12 +1024,11 @@ .format(self.site), RuntimeWarning, 2) else: self.site = site + self.mime = mime - if isinstance(mime, bool): # type(mime) == bool is deprecated. - issue_deprecation_warning( - 'Bool values of mime param in api.Request()', - depth=3, warning_class=FutureWarning, since='20201028') - self.mime = {} if mime is True else None + if isinstance(mime, bool): + raise TypeError('mime param in api.Request() must not be boolean') + self.throttle = throttle self.use_get = use_get if max_retries is None: @@ -1100,21 +1098,10 @@ 'userinfo: {!r}'.format(username, self.site.userinfo))
# MediaWiki 1.23 allows assertion for any action, - # whereas earlier WMF wikis and others used an extension which - # could only allow assert for action=edit. - # - # When we can't easily check whether the extension is loaded, - # to avoid cyclic recursion in the Pywikibot codebase, assume - # that it is present, which will cause an API warning emitted - # to the logging (console) if it is not present, but will not - # otherwise be a problem. - # This situation is only tripped when one of the first actions - # on the site is a write action and the extension isn't installed. - if (self.write and self.site.mw_version >= '1.23' - or self.action == 'edit' - and self.site.has_extension('AssertEdit')): + # make sure user is logged in + if self.write: pywikibot.debug('Adding user assertion', _logger) - self['assert'] = 'user' # make sure user is logged in + self['assert'] = 'user'
@classmethod def create_simple(cls, req_site, **kwargs): @@ -2247,14 +2234,10 @@ % self.__class__.__name__)
parameters['indexpageids'] = True # always ask for list of pageids - if self.site.mw_version < '1.21': - self.continue_name = 'query-continue' - self.continue_update = self._query_continue - else: - self.continue_name = 'continue' - self.continue_update = self._continue - # Explicitly enable the simplified continuation - parameters['continue'] = True + self.continue_name = 'continue' + self.continue_update = self._continue + # Explicitly enable the simplified continuation + parameters['continue'] = True self.request = self.request_class(**kwargs)
self.site._paraminfo.fetch('query+' + mod for mod in self.modules) @@ -3087,18 +3070,7 @@
def _update_revisions(page, revisions): """Update page revisions.""" - content_model = {'.js': 'javascript', '.css': 'css'} for rev in revisions: - if page.site.mw_version < '1.21': - # T102735: use content model depending on the page suffix - title = page.title(with_ns=False) - for suffix, cm in content_model.items(): - if title.endswith(suffix): - rev['contentmodel'] = cm - break - else: - rev['contentmodel'] = 'wikitext' - page._revisions[rev['revid']] = pywikibot.page.Revision(**rev)
diff --git a/tests/dry_api_tests.py b/tests/dry_api_tests.py index bd88503..f64ff7b 100644 --- a/tests/dry_api_tests.py +++ b/tests/dry_api_tests.py @@ -1,6 +1,6 @@ """API tests which do not interact with a site.""" # -# (C) Pywikibot team, 2012-2020 +# (C) Pywikibot team, 2012-2021 # # Distributed under the terms of the MIT license. # @@ -303,24 +303,6 @@ self.assertNotEqual(body.find(file_content), -1)
-class MimeTests(DefaultDrySiteTestCase): - - """Test MIME request handling with a real site.""" - - def test_upload_object(self): - """Test Request object prepared to upload.""" - # fake write test needs the config username - site = self.get_site() - site._username = 'myusername' - site._userinfo = {'name': 'myusername', 'groups': [], 'id': '1'} - parameters = {'action': 'upload', 'file': 'MP_sounds.png', - 'filename': join_images_path('MP_sounds.png')} - req = Request(site=site, mime=True, parameters=parameters) - with self.assertRaises(AssertionError): - assert req.mime is True - self.assertEqual(req.mime, {}) - - class ParamInfoDictTests(DefaultDrySiteTestCase):
"""Test extracting data from the ParamInfo."""
pywikibot-commits@lists.wikimedia.org