jenkins-bot has submitted this change and it was merged.

Change subject: initialize Property directly with datatype
......................................................................


initialize Property directly with datatype

the datatype is requested to the API only if the serialized snak
doesn't contain one, to speed things up.

since Claim.fromJSON() tries to detect the datatype from the snak,
snaks that reference deleted properties can be serialized correctly

bug: 54235
Change-Id: I9a36503d165f66fbb6f47985db9798dc1bb9a9a7
---
M pywikibot/page.py
1 file changed, 14 insertions(+), 5 deletions(-)

Approvals:
  John Vandenberg: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/pywikibot/page.py b/pywikibot/page.py
index c45d5b4..eb6de8c 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -3021,10 +3021,18 @@
              'quantity': pywikibot.WbQuantity,
              }
 
-    def __init__(self, site, id=None):
-        """Constructor."""
+    def __init__(self, site, id=None, datatype=None):
+        """
+        Constructor.
+
+        @param datatype: datatype of the property;
+            if not given, it will be queried via the API
+        @type datatype: basestring
+        """
         self.repo = site
         self.id = id.upper()
+        if datatype:
+            self._type = datatype
 
     @property
     def type(self):
@@ -3132,7 +3140,7 @@
     """
 
     def __init__(self, site, pid, snak=None, hash=None, isReference=False,
-                 isQualifier=False):
+                 isQualifier=False, **kwargs):
         """
         Constructor.
 
@@ -3146,7 +3154,7 @@
         @param isReference: whether specified claim is a reference
         @param isQualifier: whether specified claim is a qualifier
         """
-        Property.__init__(self, site, pid)
+        Property.__init__(self, site, pid, **kwargs)
         self.snak = snak
         self.hash = hash
         self.isReference = isReference
@@ -3170,7 +3178,8 @@
 
         @return: Claim
         """
-        claim = Claim(site, data['mainsnak']['property'])
+        claim = Claim(site, data['mainsnak']['property'],
+                      datatype=data['mainsnak'].get('datatype', None))
         if 'id' in data:
             claim.snak = data['id']
         elif 'hash' in data:

-- 
To view, visit https://gerrit.wikimedia.org/r/137737
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I9a36503d165f66fbb6f47985db9798dc1bb9a9a7
Gerrit-PatchSet: 6
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ricordisamoa <ricordisa...@openmailbox.org>
Gerrit-Reviewer: John Vandenberg <jay...@gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgr...@gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhall...@arctus.nl>
Gerrit-Reviewer: Multichill <maar...@mdammers.nl>
Gerrit-Reviewer: Ricordisamoa <ricordisa...@openmailbox.org>
Gerrit-Reviewer: Xqt <i...@gno.de>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to