jenkins-bot has submitted this change and it was merged.
Change subject: WikibasePage.get: Do not pass *args into *props
......................................................................
WikibasePage.get: Do not pass *args into *props
It has been impossible to use ItemPage.get *args
since dae1509f, as a way to load specific props.
Loading specific props is mostly unnecessary, as
all props except 'sitelinks/urls' are enabled by default,
and 'sitelinks/urls' only provides urls which are
derived from the site and page title.
If *args was used, ItemPage.get then called
WikibasePage.get(force=force, *args)
WikibasePage.get's signature provided a default for force,
which meant any value in ItemPage.get *args would become
a var arg for WikibasePage.get, causing:
TypeError: get() got multiple values for keyword argument 'force'
Instead raise NotImplementedError when *args or **kwargs contain
a value.
Continues 5cee93bb.
Bug: T115780
Change-Id: I95c86b5b67bede3ca9d19beb479a9649e5ea699e
---
M pywikibot/page.py
M tests/wikibase_tests.py
2 files changed, 55 insertions(+), 8 deletions(-)
Approvals:
XZise: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py
index d284e2c..7207a49 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -337,7 +337,9 @@
"""Return True if title of this Page is in the autoFormat
dictionary."""
return self.autoFormat()[0] is not None
- @deprecated_args(throttle=None, change_edit_time=None)
+ @deprecated_args(throttle=None,
+ change_edit_time=None,
+ expandtemplates=None)
def get(self, force=False, get_redirect=False, sysop=False):
"""Return the wiki-text of the page.
@@ -3279,15 +3281,20 @@
@param force: override caching
@type force: bool
- @param args: may be used to specify custom props.
+ @raise NotImplementedError: a value in args or kwargs
"""
+ if args or kwargs:
+ raise NotImplementedError(
+ '{0}.get does not implement var args: {1!r} and {2!r}'.format(
+ self.__class__, args, kwargs))
+
lazy_loading_id = not hasattr(self, 'id') and hasattr(self,
'_site')
if force or not hasattr(self, '_content'):
identification = self._defined_by()
if not identification:
raise pywikibot.NoPage(self)
- data = self.repo.loadcontent(identification, *args)
+ data = self.repo.loadcontent(identification)
item_index = list(data.keys())[0]
if lazy_loading_id or item_index != '-1':
self.id = item_index
@@ -3712,9 +3719,9 @@
@param get_redirect: return the item content, do not follow the
redirect, do not raise an exception.
@type get_redirect: bool
- @param args: values of props
+ @raise NotImplementedError: a value in args or kwargs
"""
- data = super(ItemPage, self).get(force=force, *args, **kwargs)
+ data = super(ItemPage, self).get(force, *args, **kwargs)
if self.isRedirectPage() and not get_redirect:
raise pywikibot.IsRedirectPage(self)
@@ -4021,15 +4028,20 @@
u"'%s' is not an property page title" % title)
Property.__init__(self, source, self.id)
- def get(self, force=False, *args):
+ def get(self, force=False, *args, **kwargs):
"""
Fetch the property entity, and cache it.
@param force: override caching
- @param args: values of props
+ @type force: bool
+ @raise NotImplementedError: a value in args or kwargs
"""
+ if args or kwargs:
+ raise NotImplementedError(
+ 'PropertyPage.get only implements "force".')
+
if force or not hasattr(self, '_content'):
- WikibasePage.get(self, force=force, *args)
+ WikibasePage.get(self, force)
self._type = self._content['datatype']
def newClaim(self, *args, **kwargs):
diff --git a/tests/wikibase_tests.py b/tests/wikibase_tests.py
index 9521f0e..1678c3b 100644
--- a/tests/wikibase_tests.py
+++ b/tests/wikibase_tests.py
@@ -24,6 +24,7 @@
unittest, TestCase,
WikidataTestCase,
DeprecationTestCase,
+ DefaultWikibaseClientTestCase,
)
from tests.basepage_tests import (
@@ -628,6 +629,40 @@
self._test_no_wikitext()
+class TestDryPageGetNotImplemented(DefaultWikibaseClientTestCase,
+ DeprecationTestCase):
+
+ """Test not implement get arguments of WikibasePage
classes."""
+
+ dry = True
+
+ def test_base_get_args(self):
+ """Test WikibasePage.get() with sysop argument."""
+ item = WikibasePage(self.repo, 'Q1')
+ # avoid loading anything
+ item._content = {}
+ self.assertRaises(NotImplementedError,
+ item.get, force=True, sysop=True)
+ self.assertRaises(NotImplementedError,
+ item.get, force=False, sysop=True)
+ self.assertRaises(NotImplementedError,
+ item.get, force=False, sysop=False)
+ self.assertRaises(NotImplementedError,
+ item.get, sysop=True)
+
+ def test_item_get_args(self):
+ """Test ItemPage.get() with sysop argument."""
+ item = pywikibot.ItemPage(self.repo, 'Q1')
+ item._content = {}
+ self.assertRaises(NotImplementedError, item.get, sysop=True)
+
+ def test_property_get_args(self):
+ """Test PropertyPage.get() with sysop argument."""
+ pp = pywikibot.PropertyPage(self.repo, 'P1')
+ pp._content = {}
+ self.assertRaises(NotImplementedError, pp.get, sysop=True)
+
+
class TestLinks(WikidataTestCase):
"""Test cases to test links stored in Wikidata.
--
To view, visit
https://gerrit.wikimedia.org/r/216535
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I95c86b5b67bede3ca9d19beb479a9649e5ea699e
Gerrit-PatchSet: 6
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipedia(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Ricordisamoa <ricordisamoa(a)openmailbox.org>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>