Skip to content

Commit

Permalink
Merge pull request #127 from zopefoundation/issue126
Browse files Browse the repository at this point in the history
Fix 'verifyObject' for class objects with staticmethods on Python 3.
  • Loading branch information
jamadden committed Oct 23, 2018
2 parents d3543ac + 705bad3 commit 706ced7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ exclude_lines =
pragma: no cover
class I[A-Z]\w+\((Interface|I[A-Z].*)\):
raise NotImplementedError
raise AssertionError
self\.fail
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Changes

- Add support for Python 3.7

- Fix ``verifyObject`` for class objects with staticmethods on
Python 3. See `issue 126
<https://github.com/zopefoundation/zope.interface/issues/126>`_.

4.5.0 (2018-04-19)
------------------
Expand Down
21 changes: 21 additions & 0 deletions src/zope/interface/tests/test_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,5 +557,26 @@ class IDummyModule(Interface):
self.assertRaises(DoesNotImplement,
self._callFUT, IDummyModule, dummy)

def test_staticmethod_hit_on_class(self):
from zope.interface import Interface
from zope.interface import provider
from zope.interface.verify import verifyObject

class IFoo(Interface):

def bar(a, b):
"The bar method"

@provider(IFoo)
class Foo(object):

@staticmethod
def bar(a, b):
raise AssertionError("We're never actually called")

# Don't use self._callFUT, we don't want to instantiate the
# class.
verifyObject(IFoo, Foo)

class OldSkool:
pass
5 changes: 4 additions & 1 deletion src/zope/interface/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,11 @@ def _verify(iface, candidate, tentative=0, vtype=None):
continue

if isinstance(attr, FunctionType):
if sys.version_info[0] >= 3 and isinstance(candidate, type):
if sys.version_info[0] >= 3 and isinstance(candidate, type) and vtype == 'c':
# This is an "unbound method" in Python 3.
# Only unwrap this if we're verifying implementedBy;
# otherwise we can unwrap @staticmethod on classes that directly
# provide an interface.
meth = fromFunction(attr, iface, name=name,
imlevel=1)
else:
Expand Down

0 comments on commit 706ced7

Please sign in to comment.