diff options
author | Alex Gaynor <alex.gaynor@gmail.com> | 2014-10-21 11:41:53 -0700 |
---|---|---|
committer | Alex Gaynor <alex.gaynor@gmail.com> | 2014-10-21 11:41:53 -0700 |
commit | 15dde27e5e14270f8e8837abe26c4ea1710bf053 (patch) | |
tree | 00b63d40d322c0f7e0868c3f43536088077741f2 | |
parent | bf940c86bf42a66320193b5bc628aa810667d4b4 (diff) | |
download | cryptography-15dde27e5e14270f8e8837abe26c4ea1710bf053.tar.gz cryptography-15dde27e5e14270f8e8837abe26c4ea1710bf053.tar.bz2 cryptography-15dde27e5e14270f8e8837abe26c4ea1710bf053.zip |
Fix for abstractproperty, and make things nicer
-rw-r--r-- | cryptography/utils.py | 15 | ||||
-rw-r--r-- | tests/test_interfaces.py | 15 |
2 files changed, 25 insertions, 5 deletions
diff --git a/cryptography/utils.py b/cryptography/utils.py index 818f4e80..e4ec6ccf 100644 --- a/cryptography/utils.py +++ b/cryptography/utils.py @@ -13,6 +13,7 @@ from __future__ import absolute_import, division, print_function +import abc import inspect import sys @@ -37,12 +38,16 @@ def verify_interface(iface, klass): raise InterfaceNotImplemented( "{0} is missing a {1!r} method".format(klass, method) ) - spec = getattr(iface, method) - actual = getattr(klass, method) - if inspect.getargspec(spec) != inspect.getargspec(actual): + if isinstance(getattr(iface, method), abc.abstractproperty): + # Can't properly verify these yet. + continue + spec = inspect.getargspec(getattr(iface, method)) + actual = inspect.getargspec(getattr(klass, method)) + if spec != actual: raise InterfaceNotImplemented( - "{0}.{1}'s signature differs from the expected".format( - klass, method + "{0}.{1}'s signature differs from the expected. Expected: " + "{2!r}. Received: {3!r}".format( + klass, method, spec, actual ) ) diff --git a/tests/test_interfaces.py b/tests/test_interfaces.py index bcc1010a..e24f4db2 100644 --- a/tests/test_interfaces.py +++ b/tests/test_interfaces.py @@ -51,3 +51,18 @@ class TestVerifyInterface(object): with pytest.raises(InterfaceNotImplemented): verify_interface(SimpleInterface, NonImplementer) + + def test_handles_abstract_property(self): + @six.add_metaclass(abc.ABCMeta) + class SimpleInterface(object): + @abc.abstractproperty + def property(self): + pass + + @register_interface(SimpleInterface) + class NonImplementer(object): + @property + def property(self): + pass + + verify_interface(SimpleInterface, NonImplementer) |