[Zope-dev] zope.interface: verifyObject vs properties

Dieter Maurer dieter at handshake.de
Fri Oct 17 14:07:10 EDT 2008


Thomas Lotze wrote at 2008-10-16 20:57 +0200:
>Christian Theune <ct at gocept.com> wrote:
>
>> Arguably, the check for an attribute would be sufficient if it checked
>> whether an attribute implementation is around -- either by a simple
>> attribute value or a descriptor providing that.
>
>At this point, I guess the outcome of the discussion depends on whether
>it is considered legal or abuse to implement a data descriptor in such
>a way that it hides an attribute defined on a base class by raising an
>AttributeError.

That is only one extreme case.

Instead, the discussion outcome depends on whether an attribute
is considered to be there when the descriptor raises an exception.
As the attribute is not accessible in this case, I argue that
it is not there: in this case, it does not have the wrong value, it
has no value at all...

>> There's another method: verifyClass. This definitely only checks the
>> presence of an implementation. 
>
>To be more precise: the declaration of implementation of an interface
>as opposed to actual implementation of its attributes.
>
>> Thomas: There is an issue that we regularly see with verifyClass that
>> makes us instanciated the objects and then use verifyObject. I don't
>> remember what it was right now. Do you?
>
>Not really, other than to avoid the case of a happy verifyClass() call
>with the application dying of a forgotten attribute implementation.
>Could there be classes we subclass that claim to implement an interface
>but don't fully do so until after instantiation? Just a guess...

Indeed: as Python lacks a means to define instance attributes on the class,
the presence of attributes can (reliably) only be checked on instances.



-- 
Dieter


More information about the Zope-Dev mailing list