verifyObject doesn't correctly work on classes with classProvides

Bug #675424 reported by Christian Zagrodnick
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
zope.interface
Won't Fix
Undecided
Unassigned

Bug Description

When for instance declaring a factory classProvides is handy at times:

>>> import zope.interface
>>> import zope.interface.verify
>>>
>>> class IFoo(zope.interface.Interface):
... def __call__(arg):
... pass
...
>>> class FooOkay(object):
... zope.interface.classProvides(IFoo)
... def __init__(self, arg):
... pass
...
>>> zope.interface.verify.verifyObject(IFoo, FooOkay)
True

That's was working.

The next case should raise an error, but doesn't. IFoo requires an arg to be passed which the following class doesn't implement:

>>> class FooVerifiedByNotLikeSpec(object):
... zope.interface.classProvides(IFoo)
...
>>> zope.interface.verify.verifyObject(IFoo, FooVerifiedByNotLikeSpec)
True

The next case should actually pass but doesn't.

>>> class FooBroken(object):
... zope.interface.classProvides(IFoo)
... def __init__(self, arg):
... pass
... def __call__(self):
... pass
...
>>> zope.interface.verify.verifyObject(IFoo, FooBroken)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/zagy/development/eggs/zope.interface-3.6.1-py2.7-macosx-10.6-x86_64.egg/zope/interface/verify.py", line 102, in verifyObject
    return _verify(iface, candidate, tentative, vtype='o')
  File "/Users/zagy/development/eggs/zope.interface-3.6.1-py2.7-macosx-10.6-x86_64.egg/zope/interface/verify.py", line 94, in _verify
    raise BrokenMethodImplementation(name, mess)
BrokenMethodImplementation: The implementation of __call__ violates its contract
        because implementation doesn't allow enough arguments.

>>>

Apparently verifyObject doesn't take any special care for classes which proivde an interface.

Revision history for this message
Tres Seaver (tseaver) wrote :
Changed in zope.interface:
status: New → Won't Fix
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.