diff options
| author | Thomas Lotze <tl@gocept.com> | 2008-10-28 17:12:35 +0000 |
|---|---|---|
| committer | Thomas Lotze <tl@gocept.com> | 2008-10-28 17:12:35 +0000 |
| commit | 8918d3c4036fb68879121ebec60ceb1bd4fc0acc (patch) | |
| tree | d8c7ccfd44ca345ee3a3f97951230af5f537a820 /src | |
| parent | 9adcef733d413babfe621814ff249fe36533bba2 (diff) | |
| download | zope-interface-8918d3c4036fb68879121ebec60ceb1bd4fc0acc.tar.gz | |
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
Diffstat (limited to 'src')
| -rw-r--r-- | src/zope/interface/verify.py | 5 | ||||
| -rw-r--r-- | src/zope/interface/verify.txt | 7 |
2 files changed, 6 insertions, 6 deletions
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: |
