diff options
| -rw-r--r-- | CHANGES.txt | 4 | ||||
| -rw-r--r-- | src/zope/interface/verify.py | 5 | ||||
| -rw-r--r-- | src/zope/interface/verify.txt | 7 |
3 files changed, 10 insertions, 6 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index e5fac67..0de4362 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -5,6 +5,10 @@ zope.interface Package Changes 3.5.1 (unreleased) ================== +- verifyObject: use getattr instead of hasattr to test for object attributes + in order to let exceptions other than AttributeError raised by properties + propagate to the caller + ================== 3.5.0 (2008-10-26) diff --git a/src/zope/interface/verify.py b/src/zope/interface/verify.py index 60eb7ea..100b43a 100644 --- a/src/zope/interface/verify.py +++ b/src/zope/interface/verify.py @@ -52,7 +52,9 @@ def _verify(iface, candidate, tentative=0, vtype=None): # Here the `desc` is either an `Attribute` or `Method` instance for name, desc in iface.namesAndDescriptions(1): - if not hasattr(candidate, name): + try: + attr = getattr(candidate, name) + except AttributeError: if (not isinstance(desc, Method)) and vtype == 'c': # We can't verify non-methods on classes, since the # class may provide attrs in it's __init__. @@ -60,7 +62,6 @@ def _verify(iface, candidate, tentative=0, vtype=None): raise BrokenImplementation(iface, name) - attr = getattr(candidate, name) if not isinstance(desc, Method): # If it's not a method, there's nothing else we can test continue diff --git a/src/zope/interface/verify.txt b/src/zope/interface/verify.txt index 4f33305..d8f9a24 100644 --- a/src/zope/interface/verify.txt +++ b/src/zope/interface/verify.txt @@ -87,8 +87,8 @@ Traceback (most recent call last): BrokenImplementation: An object has failed to implement interface <InterfaceClass __builtin__.IFoo> The x attribute was not provided. -Any other exception raised by a property should propagate to the caller of -``verifyObject``, but currently the attribute is just considered missing: +Any other exception raised by a property will propagate to the caller of +``verifyObject``: >>> class Foo(object): ... implements(IFoo) @@ -98,8 +98,7 @@ Any other exception raised by a property should propagate to the caller of >>> verifyObject(IFoo, Foo()) Traceback (most recent call last): -BrokenImplementation: An object has failed to implement interface <InterfaceClass __builtin__.IFoo> - The x attribute was not provided. +Exception Of course, broken properties that are not required by the interface don't do any harm: |
