jenkins-bot has submitted this change and it was merged.
Change subject: Support wikibase-property datatype
......................................................................
Support wikibase-property datatype
Bug: T113174
Change-Id: I87494c4662906c79a057eeab4708d1715c8668f6
---
M pywikibot/page.py
M tests/wikibase_tests.py
2 files changed, 22 insertions(+), 2 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py
index 165e7c8..e5bc63f 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -3805,6 +3805,8 @@
been looked up, the item is then defined by the qid.
"""
+ entity_type = 'item'
+
def __init__(self, site, title=None, ns=None):
"""
Constructor.
@@ -4140,6 +4142,7 @@
"""
types = {'wikibase-item': ItemPage,
+ # 'wikibase-property': PropertyPage, must be declared first
'string': basestring,
'commonsMedia': FilePage,
'globe-coordinate': pywikibot.Coordinate,
@@ -4152,6 +4155,7 @@
}
value_types = {'wikibase-item': 'wikibase-entityid',
+ 'wikibase-property': 'wikibase-entityid',
'commonsMedia': 'string',
'url': 'string',
'globe-coordinate': 'globecoordinate',
@@ -4222,6 +4226,8 @@
PropertyPage(DataSite, 'P21')
"""
+ entity_type = 'property'
+
def __init__(self, source, title=u""):
"""
Constructor.
@@ -4263,6 +4269,9 @@
return Claim(self.site, self.getID(), datatype=self.type,
*args, **kwargs)
+# Add PropertyPage to the class attribute "types" after its declaration.
+Property.types['wikibase-property'] = PropertyPage
+
class Claim(Property):
@@ -4275,6 +4284,8 @@
TARGET_CONVERTER = {
'wikibase-item': lambda value, site:
ItemPage(site, 'Q' + str(value['numeric-id'])),
+ 'wikibase-property': lambda value, site:
+ PropertyPage(site, 'P' + str(value['numeric-id'])),
'commonsMedia': lambda value, site:
FilePage(pywikibot.Site('commons', 'commons'), value),
'globe-coordinate': pywikibot.Coordinate.fromWikibase,
@@ -4690,8 +4701,8 @@
@return: JSON value
@rtype: dict
"""
- if self.type == 'wikibase-item':
- value = {'entity-type': 'item',
+ if self.type in ('wikibase-item', 'wikibase-property'):
+ value = {'entity-type': self.getTarget().entity_type,
'numeric-id': self.getTarget().getID(numeric=True)}
elif self.type in ('string', 'url', 'math',
'external-id'):
value = self.getTarget()
diff --git a/tests/wikibase_tests.py b/tests/wikibase_tests.py
index f428475..58bab75 100644
--- a/tests/wikibase_tests.py
+++ b/tests/wikibase_tests.py
@@ -702,6 +702,15 @@
claim = property_page.newClaim()
self.assertEqual(claim.type, 'wikibase-item')
+ def test_as_target(self):
+ """Test that PropertyPage can be used as a
value."""
+ wikidata = self.get_repo()
+ property_page = pywikibot.PropertyPage(wikidata, 'P1687')
+ claim = property_page.newClaim()
+ claim.setTarget(property_page)
+ self.assertEqual(claim.type, 'wikibase-property')
+ self.assertEqual(claim.target, property_page)
+
class TestClaimSetValue(WikidataTestCase):
--
To view, visit
https://gerrit.wikimedia.org/r/321377
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I87494c4662906c79a057eeab4708d1715c8668f6
Gerrit-PatchSet: 6
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <Ladsgroup(a)gmail.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Ricordisamoa <ricordisamoa(a)openmailbox.org>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>