diff options
Diffstat (limited to 'src/zope/interface/declarations.py')
-rw-r--r-- | src/zope/interface/declarations.py | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/src/zope/interface/declarations.py b/src/zope/interface/declarations.py index de90074..9c06a16 100644 --- a/src/zope/interface/declarations.py +++ b/src/zope/interface/declarations.py @@ -1258,10 +1258,20 @@ def providedBy(ob): @_use_c_impl class ObjectSpecificationDescriptor(object): - """Implement the `__providedBy__` attribute - - The `__providedBy__` attribute computes the interfaces provided by - an object. + """Implement the ``__providedBy__`` attribute + + The ``__providedBy__`` attribute computes the interfaces provided by + an object. If an object has an ``__provides__`` attribute, that is returned. + Otherwise, `implementedBy` the *cls* is returned. + + .. versionchanged:: 5.4.0 + Both the default (C) implementation and the Python implementation + now let exceptions raised by accessing ``__provides__`` propagate. + Previously, the C version ignored all exceptions. + .. versionchanged:: 5.4.0 + The Python implementation now matches the C implementation and lets + a ``__provides__`` of ``None`` override what the class is declared to + implement. """ def __get__(self, inst, cls): @@ -1270,11 +1280,10 @@ class ObjectSpecificationDescriptor(object): if inst is None: return getObjectSpecification(cls) - provides = getattr(inst, '__provides__', None) - if provides is not None: - return provides - - return implementedBy(cls) + try: + return inst.__provides__ + except AttributeError: + return implementedBy(cls) ############################################################################## |