Ricordisamoa has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/135400

Change subject: use isinstance(obj, typ) instead of type(obj) == typ
......................................................................

use isinstance(obj, typ) instead of type(obj) == typ

it supports inheritance

Change-Id: I935c78736e9bfa995a62a88cc4c9a0c581ba0f60
---
M pywikibot/bot.py
M pywikibot/data/api.py
M pywikibot/i18n.py
M pywikibot/site.py
M scripts/checkimages.py
M scripts/commonscat.py
M scripts/featured.py
M scripts/interwiki.py
8 files changed, 16 insertions(+), 16 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/00/135400/1

diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index e8487e2..2e7e859 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -626,7 +626,7 @@
             try:
                 _arg, _val = arg[1:].split(':')
                 # explicitly check for int (so bool doesn't match)
-                if type(getattr(config, _arg)) is not int:
+                if not isinstance(getattr(config, _arg), int):
                     raise TypeError
                 setattr(config, _arg, int(_val))
             except (ValueError, TypeError, AttributeError):
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index 5ef6cee..a0f5aeb 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -350,7 +350,7 @@
                 continue
             if not result:
                 result = {}
-            if type(result) is not dict:
+            if not isinstance(result, dict):
                 raise APIError("Unknown",
                                "Unable to process query response of type %s."
                                % type(result),
diff --git a/pywikibot/i18n.py b/pywikibot/i18n.py
index 3ec974b..a7dd59b 100644
--- a/pywikibot/i18n.py
+++ b/pywikibot/i18n.py
@@ -242,7 +242,7 @@
                              "occurences.")
         i = 0
         for selector, variants in plural_items:
-            if type(parameters) == dict:
+            if isinstance(parameters, dict):
                 num = int(parameters[selector])
             elif isinstance(parameters, basestring):
                 num = int(parameters)
@@ -299,7 +299,7 @@
         code = code.code
 
     # Check whether xdict has multiple projects
-    if type(xdict) == dict:
+    if isinstance(xdict, dict):
         if family in xdict:
             xdict = xdict[family]
         elif 'wikipedia' in xdict:
@@ -307,7 +307,7 @@
 
     # Get the translated string
     trans = None
-    if type(xdict) != dict:
+    if not isinstance(xdict, dict):
         trans = xdict
     elif code in xdict:
         trans = xdict[code]
@@ -355,7 +355,7 @@
     if hasattr(code, 'code'):
         lang = code.code
     # check whether we need the language code back
-    elif type(code) == list:
+    elif isinstance(code, list):
         lang = code.pop()
         code_needed = True
     else:
@@ -455,7 +455,7 @@
     # check for PLURAL variants
     trans = _extract_plural(lang, trans, parameters)
     # we always have a dict for replacement of translatewiki messages
-    if parameters and type(parameters) == dict:
+    if parameters and isinstance(parameters, dict):
         try:
             return trans % parameters
         except KeyError:
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 9599d4c..e6743b2 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -416,16 +416,16 @@
         else:
             ns2, name2 = 0, title2
         for space in self.namespaces():  # iterate over all valid namespaces
-            if type(ns1) is not int and valid_namespace(ns1, space):
+            if not isinstance(ns1, int) and valid_namespace(ns1, space):
                 ns1 = space
-            if type(ns2) is not int and valid_namespace(ns2, space):
+            if not isinstance(ns2, int) and valid_namespace(ns2, space):
                 ns2 = space
-        if type(ns1) is not int:
+        if not isinstance(ns1, int):
             # no valid namespace prefix found, so the string followed by ":"
             # must be part of the title
             name1 = ns1 + ":" + name1
             ns1 = 0
-        if type(ns2) is not int:
+        if not isinstance(ns2, int):
             name2 = ns2 + ":" + name2
             ns2 = 0
         if ns1 != ns2:
@@ -3585,7 +3585,7 @@
     @deprecated("pywikibot.WikibasePage")
     def get_item(self, source, **params):
         """get the data for multiple Wikibase items"""
-        if type(source) == int or \
+        if isinstance(source, int) or \
            isinstance(source, basestring) and source.isdigit():
             ids = 'q' + str(source)
             wbrequest = api.Request(site=self, action="wbgetentities", ids=ids,
diff --git a/scripts/checkimages.py b/scripts/checkimages.py
index 64a90d5..d781a7e 100644
--- a/scripts/checkimages.py
+++ b/scripts/checkimages.py
@@ -930,7 +930,7 @@
     def countEdits(self, pagename, userlist):
         """Function to count the edit of a user or a list of users in a 
page."""
         # self.botolist
-        if type(userlist) == str:
+        if isinstance(userlist, basestring):
             userlist = [userlist]
         page = pywikibot.Page(self.site, pagename)
         history = page.getVersionHistory()
diff --git a/scripts/commonscat.py b/scripts/commonscat.py
index 27e98a2..04569f1 100755
--- a/scripts/commonscat.py
+++ b/scripts/commonscat.py
@@ -336,7 +336,7 @@
             templatesInThePage = page.templates()
             templatesWithParams = page.templatesWithParams()
             for template in ignoreTemplates[page.site.language()]:
-                if type(template) != tuple:
+                if not isinstance(template, tuple):
                     for pageTemplate in templatesInThePage:
                         if pageTemplate.title(withNamespace=False) == template:
                             return True
diff --git a/scripts/featured.py b/scripts/featured.py
index f56e63c..a056a40 100644
--- a/scripts/featured.py
+++ b/scripts/featured.py
@@ -92,7 +92,7 @@
     except pywikibot.PageNotFound:
         return
     cat = pywikibot.Category(site, title)
-    if type(hide) == dict:
+    if isinstance(hide, dict):
         hide = hide.get(site.code)
     for article in cat.articles(endsort=hide):
         yield article
diff --git a/scripts/interwiki.py b/scripts/interwiki.py
index 3c2dfe4..df70c62 100755
--- a/scripts/interwiki.py
+++ b/scripts/interwiki.py
@@ -2390,7 +2390,7 @@
         tmpl, loc = moved_links[page.site.lang]
     except KeyError:
         pass
-    if type(tmpl) != list:
+    if not isinstance(tmpl, list):
         tmpl = [tmpl]
     try:
         tmpl += ignoreTemplates[page.site.lang]

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I935c78736e9bfa995a62a88cc4c9a0c581ba0f60
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ricordisamoa <ricordisa...@live.it>

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

Reply via email to