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

Change subject: Use Namespace as a key into Site.namespaces
......................................................................


Use Namespace as a key into Site.namespaces

Existing code uses a namespace variable, consisting of an int, as
a key into the Site.namespaces dict.  In order to change these
namespace variables to be a Namespace object instead of an int,
the Namespace object needs to be usable as a key.

Change-Id: Ib30da3c1e8fb0fef2e5efd8d06313f8852802934
---
M pywikibot/site.py
M tests/namespace_tests.py
2 files changed, 6 insertions(+), 0 deletions(-)

Approvals:
  John Vandenberg: Looks good to me, but someone else must approve
  XZise: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/pywikibot/site.py b/pywikibot/site.py
index 3717449..8cf9f60 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -299,6 +299,9 @@
     def __index__(self):
         return self.id
 
+    def __hash__(self):
+        return self.id
+
     def __eq__(self, other):
         """Compare whether two namespace objects are equal."""
         if isinstance(other, int):
diff --git a/tests/namespace_tests.py b/tests/namespace_tests.py
index e3c3f60..c33a6e3 100644
--- a/tests/namespace_tests.py
+++ b/tests/namespace_tests.py
@@ -81,6 +81,9 @@
         self.assertTrue(all(Namespace.lookup_name(b, ns).id == 
self.all_builtin_ids[b]
                             for b in self.all_builtin_ids))
 
+        # Use a namespace object as a dict key
+        self.assertEqual(ns[ns[6]], ns[6])
+
     def testNamespaceConstructor(self):
         kwargs = {u'case': u'first-letter'}
         y = Namespace(id=6, custom_name=u'dummy', canonical_name=u'File',

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ib30da3c1e8fb0fef2e5efd8d06313f8852802934
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: Merlijn van Deen <[email protected]>
Gerrit-Reviewer: XZise <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to