[Zope3-Users] Dynamic Typing: Are checks on interface compliance possible?

Marco Mariani marco at sferacarta.com
Thu May 18 09:30:25 EDT 2006


Stephan Richter wrote:

> In addition there is the FieldProperty class, which can be used to enforce a 
> value. I have recently started to use it all the time. I really like it too.

It also sets the attributes to the default values inside the tests,
taking them from the interface definition instead of the class definition..



class MyObject:
   implements(IMyObject)

   what = 42



vs.


class IMyObject(Interface):
   what = Int(title=u"Whatever",default=42)

class MyObject:
    """

    >>> from zope.interface.verify import verifyClass
    >>> verifyClass(IMyObject, MyObject)
    True

    Try changing the attributes:

    >>> obj = MyObject()
    >>> obj.what
    42
    >>> obj.what=56
    >>> obj.what
    56

    """


   implements(IMyObject)

   what = FieldProperty(IMyObject['what'])




More information about the Zope3-users mailing list