Lokal Profil has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/364728 )

Change subject: Use WbUnknown when encountering an unknown data type
......................................................................

Use WbUnknown when encountering an unknown data type

@Todo:
* Unittests

Bug: T165996
Change-Id: I54d9a830d80f1ba6d91416b7e72b9a51d18d6e31
---
M pywikibot/page.py
M tests/paraminfo_tests.py
2 files changed, 13 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/28/364728/1

diff --git a/pywikibot/page.py b/pywikibot/page.py
index 32663d6..95c93a4 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -4470,6 +4470,7 @@
              'tabular-data': pywikibot.WbTabularData,
              }
 
+    # the value type where different from the type
     value_types = {'wikibase-item': 'wikibase-entityid',
                    'wikibase-property': 'wikibase-entityid',
                    'commonsMedia': 'string',
@@ -4672,8 +4673,13 @@
         if claim.getSnakType() == 'value':
             value = data['mainsnak']['datavalue']['value']
             # The default covers string, url types
-            claim.target = cls.TARGET_CONVERTER.get(
-                claim.type, lambda value, site: value)(value, site)
+            if claim.type in cls.types or claim.type == 'wikibase-property':
+                claim.target = cls.TARGET_CONVERTER.get(
+                    claim.type, lambda value, site: value)(value, site)
+            else:
+                pywikibot.warning(
+                    '{} datatype is not supported yet.'.format(claim.type))
+                claim.target = pywikibot.WbUnknown.fromWikibase(value)
         if 'rank' in data:  # References/Qualifiers don't have ranks
             claim.rank = data['rank']
         if 'references' in data:
@@ -5043,9 +5049,10 @@
                            'quantity', 'monolingualtext',
                            'geo-shape', 'tabular-data'):
             value = self.getTarget().toWikibase()
-        else:
-            raise NotImplementedError('%s datatype is not supported yet.'
-                                      % self.type)
+        else:  # WbUnknown
+            pywikibot.warning(
+                '{} datatype is not supported yet.'.format(self.type))
+            value = self.getTarget().toWikibase()
         return value
 
     def _formatDataValue(self):
diff --git a/tests/paraminfo_tests.py b/tests/paraminfo_tests.py
index e2e4263..e221120 100644
--- a/tests/paraminfo_tests.py
+++ b/tests/paraminfo_tests.py
@@ -227,6 +227,7 @@
         known = ['item', 'property']
         self._check_param_values(self.repo, 'wbsearchentities', 'type', known)
 
+    # Missing datatypes won't crash pywikibot but should be noted
     def test_datatypes(self):
         """Test that all encountered datatypes are known."""
         unsupported = set()

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I54d9a830d80f1ba6d91416b7e72b9a51d18d6e31
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Lokal Profil <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to