jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/536640 )

Change subject: [IMPR] Simplify some Namespace methods
......................................................................

[IMPR] Simplify some Namespace methods

- replace "'' + name" with "name"
- return False in __eq__ if no instance type match
- change calc sequence or add and sub
- use boolean result directly instead of comparing with empty string

Change-Id: I323454aaeaaf5535e6de630983357ca5d3ef8e05
---
M pywikibot/site.py
1 file changed, 17 insertions(+), 13 deletions(-)

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



diff --git a/pywikibot/site.py b/pywikibot/site.py
index f63c034..1536cd4 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -305,10 +305,11 @@
         """Return the name with required colons, depending on the ID."""
         if id == 0:
             return ':'
-        elif id in (6, 14):
+
+        if id in (6, 14):
             return ':' + name + ':'
-        else:
-            return '' + name + ':'
+
+        return name + ':'

     def __str__(self):
         """Return the canonical string representation."""
@@ -342,11 +343,15 @@
         """Compare whether two namespace objects are equal."""
         if isinstance(other, int):
             return self.id == other
-        elif isinstance(other, Namespace):
+
+        if isinstance(other, Namespace):
             return self.id == other.id
-        elif isinstance(other, UnicodeType):
+
+        if isinstance(other, UnicodeType):
             return other in self

+        return False
+
     def __ne__(self, other):
         """Compare whether two namespace objects are not equal."""
         return not self.__eq__(other)
@@ -357,11 +362,11 @@

     def __sub__(self, other):
         """Apply subtraction on the namespace id."""
-        return -(other) + self.id
+        return self.id - other

     def __add__(self, other):
         """Apply addition on the namespace id."""
-        return other + self.id
+        return self.id + other

     def _cmpkey(self):
         """Return the ID as a comparison key."""
@@ -420,17 +425,16 @@

         parts = name.split(':', 4)
         count = len(parts)
-        if count > 3:
+        if count > 3 or (count == 3 and parts[2]):
             return False
-        elif count == 3:
-            if parts[2] != '':
-                return False

         # Discard leading colon
-        if count >= 2 and parts[0] == '' and parts[1]:
+        if count >= 2 and not parts[0] and parts[1]:
             return parts[1].strip()
-        elif parts[0]:
+
+        if parts[0]:
             return parts[0].strip()
+
         return False

     @classmethod

--
To view, visit https://gerrit.wikimedia.org/r/536640
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I323454aaeaaf5535e6de630983357ca5d3ef8e05
Gerrit-Change-Number: 536640
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Framawiki <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot (75)
Gerrit-CC: Lokal Profil <[email protected]>
Gerrit-CC: Matěj Suchánek <[email protected]>
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to