[Zope-dev] zope.interface: verifyObject vs properties
Thomas Lotze
tl at gocept.com
Wed Oct 15 03:27:02 EDT 2008
There has been a problem with zope.interface's verifyObject function
that occurs in conjunction with Python properties: when verifyObject
checks for the presence of an object's attribute, it does so by using
hasattr() which in turn tries a getattr() call. If the attribute is
implemented as a property, this may raise an exception which will be
masked by hasattr() due to a bare except: clause. One scenario where
this is a problem is a property that performs some component lookup
which will succeed at application runtime but not in unit tests where
verifyObject is commonly used.
While it has also been argued that behaviour so complex that it may
raise an Exception should not be implemented as a property in the
first place, we believe that verifyObject should handle this case better
than it currently does. A possible fix would be to add an additional
check for a data descriptor on the object's class if the hasattr() test
returns False.
Are there any objections against modifying verifyObject in this way?
Thomas
--
Thomas Lotze · tl at gocept.com
gocept gmbh & co. kg · forsterstraße 29 · 06112 halle (saale) · germany
http://gocept.com · tel +49 345 1229889 0 · fax +49 345 1229889 1
Zope and Plone consulting and development
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.zope.org/pipermail/zope-dev/attachments/20081015/4a4d76ab/attachment-0001.bin
More information about the Zope-Dev
mailing list