From f41ebfdb0b432fd99e1c44c0a1d7fd54a637bdf8 Mon Sep 17 00:00:00 2001 From: Jason Madden Date: Mon, 27 Jan 2020 09:31:30 -0600 Subject: Remove support for hashing uninitialized interfaces. Fixes #157 --- src/zope/interface/interface.py | 9 ++------- src/zope/interface/tests/test_interface.py | 12 ++---------- 2 files changed, 4 insertions(+), 17 deletions(-) (limited to 'src/zope') diff --git a/src/zope/interface/interface.py b/src/zope/interface/interface.py index 106a60d..7fa56aa 100644 --- a/src/zope/interface/interface.py +++ b/src/zope/interface/interface.py @@ -17,7 +17,6 @@ import sys from types import MethodType from types import FunctionType -import warnings import weakref from zope.interface._compat import _use_c_impl @@ -579,7 +578,7 @@ class InterfaceClass(Element, InterfaceBase, Specification): if other is None: return -1 - n1 = (getattr(self, '__name__', ''), getattr(self, '__module__', '')) + n1 = (self.__name__, self.__module__) n2 = (getattr(other, '__name__', ''), getattr(other, '__module__', '')) # This spelling works under Python3, which doesn't have cmp(). @@ -589,11 +588,7 @@ class InterfaceClass(Element, InterfaceBase, Specification): try: return self._v_cached_hash except AttributeError: - try: - self._v_cached_hash = hash((self.__name__, self.__module__)) - except AttributeError: # pragma: no cover - warnings.warn('Hashing uninitialized InterfaceClass instance') - return 1 + self._v_cached_hash = hash((self.__name__, self.__module__)) return self._v_cached_hash def __eq__(self, other): diff --git a/src/zope/interface/tests/test_interface.py b/src/zope/interface/tests/test_interface.py index f5a57b4..3bf26dc 100644 --- a/src/zope/interface/tests/test_interface.py +++ b/src/zope/interface/tests/test_interface.py @@ -834,20 +834,12 @@ class InterfaceClassTests(unittest.TestCase): 'zope.interface.tests.test_interface')))) def test___hash___missing_required_attrs(self): - import warnings - from warnings import catch_warnings - class Derived(self._getTargetClass()): def __init__(self): pass # Don't call base class. derived = Derived() - with catch_warnings(record=True) as warned: - warnings.simplefilter('always') # see LP #825249 - self.assertEqual(hash(derived), 1) - self.assertEqual(len(warned), 1) - self.assertTrue(warned[0].category is UserWarning) - self.assertEqual(str(warned[0].message), - 'Hashing uninitialized InterfaceClass instance') + with self.assertRaises(AttributeError): + hash(derived) def test_comparison_with_None(self): iface = self._makeOne() -- cgit v1.2.1