summaryrefslogtreecommitdiff
path: root/src/zope/interface/interface.py
diff options
context:
space:
mode:
authorTres Seaver <tseaver@palladion.com>2011-08-11 19:49:19 +0000
committerTres Seaver <tseaver@palladion.com>2011-08-11 19:49:19 +0000
commit05a899a8275bbd6b2e332a4fbfeab4d7e1dc40f8 (patch)
tree003d20205db43dbe9d15a19b291cde66e2d65360 /src/zope/interface/interface.py
parent0f7eb19312fa4cc67dab35b539a83fd89609b428 (diff)
downloadzope-interface-05a899a8275bbd6b2e332a4fbfeab4d7e1dc40f8.tar.gz
Work around buggy behavior in some subclasses of `InterfaceClass``
Some sublcasses invoke '__hash__' before initializing '__module__' and '__name__'. The workaround returns a fixed constant hash in such cases, and issues a UserWarning. Addresses LP #811792.
Diffstat (limited to 'src/zope/interface/interface.py')
-rw-r--r--src/zope/interface/interface.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/zope/interface/interface.py b/src/zope/interface/interface.py
index 6b2d513..af76f12 100644
--- a/src/zope/interface/interface.py
+++ b/src/zope/interface/interface.py
@@ -17,6 +17,7 @@ from __future__ import generators
import sys
from types import FunctionType
+import warnings
import weakref
from zope.interface.exceptions import Invalid
@@ -682,6 +683,10 @@ class InterfaceClass(Element, InterfaceBase, Specification):
return (n1 > n2) - (n1 < n2)
def __hash__(self):
+ d = self.__dict__
+ if '__module__' not in d or '__name__' not in d:
+ warnings.warn('Hashing uninitialized InterfaceClass instance')
+ return 1
return hash((self.__name__, self.__module__))
def __eq__(self, other):