[Zope-Checkins] CVS: Zope3/lib/python/Interface - Exceptions.py:1.6.134.2 iclass.py:1.11.58.3
Jim Fulton
jim@zope.com
Mon, 17 Dec 2001 10:23:09 -0500
Update of /cvs-repository/Zope3/lib/python/Interface
In directory cvs.zope.org:/tmp/cvs-serv28650
Modified Files:
Tag: Zope-3x-branch
Exceptions.py iclass.py
Log Message:
Fixed bug in code for iterating over implemented interfaces.
A common bug is to assign a module to an __implements__
attribute when one intended to assin a module variable.
The error message was not very helpful.
Changed code to raise a more informative error
and added tests.
=== Zope3/lib/python/Interface/Exceptions.py 1.6.134.1 => 1.6.134.2 ===
""" % self.__dict__
-class InvalidInterface(Exception): pass
+class InvalidInterface(Exception):
+ """The interface has invalid contents
+ """
+
+
+class BadImplements(TypeError):
+ """An implementation assertion is invalid
+
+ because it doesn't contain an interface or a sequence of valid
+ implementation assertions.
+ """
=== Zope3/lib/python/Interface/iclass.py 1.11.58.2 => 1.11.58.3 ===
_typeImplements={}
-
+TupleType=type(())
def getImplements(object, tiget=_typeImplements.get):
t = type(object)
@@ -83,13 +83,16 @@
i = getInterface(object, implements)
if i is not None:
return visitImplements(i, object, visitor, getInterface)
- else:
- # A sequence of interfaces.
+ elif type(implements) is TupleType:
for i in implements:
r = visitImplements(i, object, visitor, getInterface)
if r:
# If the visitor returns anything true, stop.
return r
+ else:
+ raise Exceptions.BadImplements(
+ """__implements__ should be an interface or tuple,
+ not a %s""" % implements.__class__.__name__)
return None