[Checkins] SVN: zope.interface/trunk/ LP 804951: InterfaceClass instances were unhashable under Python 3.x.

Tres Seaver tseaver at palladion.com
Tue Jul 5 13:06:09 EDT 2011


Log message for revision 122111:
  LP 804951:  InterfaceClass instances were unhashable under Python 3.x.
  

Changed:
  U   zope.interface/trunk/CHANGES.txt
  U   zope.interface/trunk/src/zope/interface/interface.py
  U   zope.interface/trunk/src/zope/interface/tests/test_interface.py

-=-
Modified: zope.interface/trunk/CHANGES.txt
===================================================================
--- zope.interface/trunk/CHANGES.txt	2011-07-05 13:25:01 UTC (rev 122110)
+++ zope.interface/trunk/CHANGES.txt	2011-07-05 17:06:09 UTC (rev 122111)
@@ -4,7 +4,7 @@
 3.6.4 (unreleased)
 ------------------
 
-- TBD
+- LP 804951:  InterfaceClass instances were unhashable under Python 3.x.
 
 3.6.3 (2011-05-26)
 ------------------

Modified: zope.interface/trunk/src/zope/interface/interface.py
===================================================================
--- zope.interface/trunk/src/zope/interface/interface.py	2011-07-05 13:25:01 UTC (rev 122110)
+++ zope.interface/trunk/src/zope/interface/interface.py	2011-07-05 17:06:09 UTC (rev 122111)
@@ -681,6 +681,9 @@
         # This spelling works under Python3, which doesn't have cmp().
         return (n1 > n2) - (n1 < n2)
 
+    def __hash__(self):
+        return hash((self.__name__, self.__module__))
+
     def __eq__(self, other):
         c = self.__cmp(self, other)
         return c == 0

Modified: zope.interface/trunk/src/zope/interface/tests/test_interface.py
===================================================================
--- zope.interface/trunk/src/zope/interface/tests/test_interface.py	2011-07-05 13:25:01 UTC (rev 122110)
+++ zope.interface/trunk/src/zope/interface/tests/test_interface.py	2011-07-05 17:06:09 UTC (rev 122111)
@@ -381,7 +381,16 @@
         self.failUnless(IEmpty >= IEmpty)
         self.failIf(IEmpty > IEmpty)
 
+    def test_hash(self):
+        from zope.interface import Interface
 
+        class IEmpty(Interface):
+            pass
+
+        self.assertEqual(hash(IEmpty),
+                         hash((IEmpty.__name__, IEmpty.__module__)))
+
+
 if sys.version_info >= (2, 4):
 
     def test_invariant_as_decorator():



More information about the checkins mailing list