jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/959678 )

Change subject: [cleanup] remove mw 1.14 and mw 1.22 Siteinfo fallback 
implementation
......................................................................

[cleanup] remove mw 1.14 and mw 1.22 Siteinfo fallback implementation

Siteinfo._get_default was introduced to support defaults for
'restrictions' (introduced with mw 1.23) and 'fileextensions'
(introduces with mw 1.15). These fallbacks can be dropped.

This partly reverts 0f1c546 and f7a399e

Change-Id: I961c25bf06d7608f51af98e50a94431f0b475075
---
M tests/utils.py
M pywikibot/site/_siteinfo.py
M tests/siteinfo_tests.py
3 files changed, 30 insertions(+), 45 deletions(-)

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




diff --git a/pywikibot/site/_siteinfo.py b/pywikibot/site/_siteinfo.py
index 4aa01df..6585c3e 100644
--- a/pywikibot/site/_siteinfo.py
+++ b/pywikibot/site/_siteinfo.py
@@ -12,6 +12,7 @@
 from typing import Any, Optional, Union

 import pywikibot
+from pywikibot.backports import Dict, List
 from pywikibot.exceptions import APIError
 from pywikibot.tools.collections import EMPTY_DEFAULT

@@ -58,7 +59,7 @@
     def __init__(self, site) -> None:
         """Initialise it with an empty cache."""
         self._site = site
-        self._cache = {}
+        self._cache: Dict[str, Any] = {}

     def clear(self) -> None:
         """Remove all items from Siteinfo.
@@ -68,37 +69,6 @@
         self._cache.clear()

     @staticmethod
-    def _get_default(key: str):
-        """
-        Return the default value for different properties.
-
-        If the property is 'restrictions' it returns a dictionary with:
-         - 'cascadinglevels': 'sysop'
-         - 'semiprotectedlevels': 'autoconfirmed'
-         - 'levels': '' (everybody), 'autoconfirmed', 'sysop'
-         - 'types': 'create', 'edit', 'move', 'upload'
-        Otherwise it returns :py:obj:`tools.EMPTY_DEFAULT`.
-
-        :param key: The property name
-        :return: The default value
-        :rtype: dict or :py:obj:`tools.EmptyDefault`
-        """
-        if key == 'restrictions':
-            # implemented in b73b5883d486db0e9278ef16733551f28d9e096d
-            return {
-                'cascadinglevels': ['sysop'],
-                'semiprotectedlevels': ['autoconfirmed'],
-                'levels': ['', 'autoconfirmed', 'sysop'],
-                'types': ['create', 'edit', 'move', 'upload']
-            }
-
-        if key == 'fileextensions':
-            # the default file extensions in MediaWiki
-            return [{'ext': ext} for ext in ['png', 'gif', 'jpg', 'jpeg']]
-
-        return EMPTY_DEFAULT
-
-    @staticmethod
     def _post_process(prop, data) -> None:
         """Do some default handling of data. Directly modifies data."""
         # Be careful with version tests inside this here as it might need to
@@ -150,7 +120,7 @@
         if not props:
             raise ValueError('At least one property name must be provided.')

-        invalid_properties = []
+        invalid_properties: List[str] = []
         request = self._site._request(
             expiry=pywikibot.config.API_config_expiry
             if expiry is False else expiry,
@@ -168,7 +138,7 @@
                 if len(props) == 1:
                     pywikibot.log(
                         f"Unable to get siprop '{props[0]}'")
-                    return {props[0]: (Siteinfo._get_default(props[0]), False)}
+                    return {props[0]: (EMPTY_DEFAULT, False)}
                 pywikibot.log('Unable to get siteinfo, because at least '
                               "one property is unknown: '{}'".format(
                                   "', '".join(props)))
@@ -181,7 +151,7 @@
             result = {}
             if invalid_properties:
                 for prop in invalid_properties:
-                    result[prop] = (Siteinfo._get_default(prop), False)
+                    result[prop] = (EMPTY_DEFAULT, False)
                 pywikibot.log("Unable to get siprop(s) '{}'".format(
                     "', '".join(invalid_properties)))
             if 'query' in data:
diff --git a/tests/siteinfo_tests.py b/tests/siteinfo_tests.py
index 020cf2e..f39a6c5 100755
--- a/tests/siteinfo_tests.py
+++ b/tests/siteinfo_tests.py
@@ -53,20 +53,17 @@
         self.assertIsInstance(mysite.namespaces[0].subpages, bool)
         self.assertIsInstance(mysite.namespaces[0].content, bool)

-    def test_properties_with_defaults(self):
-        """Test the siteinfo properties with defaults."""
-        # This does not test that the defaults work correct,
-        # unless the default site is a version needing these defaults
+    def test_properties(self):
+        """Test the siteinfo properties."""
         # 'fileextensions' introduced in v1.15:
-        self.assertIsInstance(self.site.siteinfo.get('fileextensions'), list)
         self.assertIn('fileextensions', self.site.siteinfo)
         fileextensions = self.site.siteinfo.get('fileextensions')
+        self.assertIsInstance(fileextensions, list)
         self.assertIn({'ext': 'png'}, fileextensions)
         # 'restrictions' introduced in v1.23:
-        mysite = self.site
-        self.assertIsInstance(mysite.siteinfo.get('restrictions'), dict)
-        self.assertIn('restrictions', mysite.siteinfo)
+        self.assertIn('restrictions', self.site.siteinfo)
         restrictions = self.site.siteinfo.get('restrictions')
+        self.assertIsInstance(restrictions, dict)
         self.assertIn('cascadinglevels', restrictions)

     def test_no_cache(self):
diff --git a/tests/utils.py b/tests/utils.py
index 6d76c97..8c0ce06 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -20,6 +20,7 @@
 from pywikibot.data.api import Request as _original_Request
 from pywikibot.exceptions import APIError
 from pywikibot.login import LoginStatus
+from pywikibot.tools.collections import EMPTY_DEFAULT
 from pywikibot.site import Namespace
 from pywikibot.tools import PYTHON_VERSION

@@ -277,7 +278,7 @@
             return loaded[0]

         if get_default:
-            default = pywikibot.site.Siteinfo._get_default(key)
+            default = EMPTY_DEFAULT
             if cache:
                 self._cache[key] = (default, False)
             return default
@@ -342,7 +343,9 @@
         super().__init__(code, fam, user)
         self._userinfo = pywikibot.tools.collections.EMPTY_DEFAULT
         self._paraminfo = DryParamInfo()
-        self._siteinfo = DummySiteinfo({})
+        # setup a default siteinfo used by dry tests
+        default_siteinfo = {'fileextensions': [{'ext': 'jpg'}]}
+        self._siteinfo = DummySiteinfo(default_siteinfo)
         self._siteinfo._cache['lang'] = (code, True)
         self._siteinfo._cache['case'] = (
             'case-sensitive' if self.family.name == 'wiktionary' else

--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/959678
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I961c25bf06d7608f51af98e50a94431f0b475075
Gerrit-Change-Number: 959678
Gerrit-PatchSet: 7
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to