[Checkins] SVN: z3c.persistentfactory/trunk/z3c/persistentfactory/ * Declarer's declarations don't track with changes to the

Ross Patterson me at rpatterson.net
Thu Apr 10 16:04:53 EDT 2008


Log message for revision 85221:
  
  * Declarer's declarations don't track with changes to the
    class method's declarations.
  
  * Isolate declarations on the declarer's class from declarations on
    instances.
  

Changed:
  U   z3c.persistentfactory/trunk/z3c/persistentfactory/declarations.py
  U   z3c.persistentfactory/trunk/z3c/persistentfactory/declarations.txt
  U   z3c.persistentfactory/trunk/z3c/persistentfactory/factory.py
  U   z3c.persistentfactory/trunk/z3c/persistentfactory/factory.txt

-=-
Modified: z3c.persistentfactory/trunk/z3c/persistentfactory/declarations.py
===================================================================
--- z3c.persistentfactory/trunk/z3c/persistentfactory/declarations.py	2008-04-10 19:08:46 UTC (rev 85220)
+++ z3c.persistentfactory/trunk/z3c/persistentfactory/declarations.py	2008-04-10 20:04:52 UTC (rev 85221)
@@ -7,34 +7,40 @@
     def __reduce__(self):
         return Implements, self.__bases__
 
-class ImplementsDescriptor(object):
+class ImplementsDescriptor(declarations.Implements):
 
     def __get__(self, instance, owner):
         if instance is None:
+            return self
+
+        if '__implemented__' not in instance.__dict__:
             raise AttributeError('__implemented__')
 
-        if '__implemented__' not in instance.__dict__:
-            instance.__implemented__ = interface.implementedBy(
-                instance.__call__)
         return instance.__dict__['__implemented__']
     
     def __set__(self, instance, value):
-        instance.__dict__['__implemented__'] = Implements(*value)
+        if not isinstance(value, Implements):
+            value = Implements(*value)
 
+        instance.__dict__['__implemented__'] = value
+
     def __delete__(self, instance):
         if '__implemented__' not in instance.__dict__:
             raise AttributeError('__implemented__')
+
         del instance.__dict__['__implemented__']
 
-class AdaptsDescriptor(object):
+class Declarer(object):
 
-    def __get__(self, instance, owner):
-        if instance is None:
-            raise AttributeError('__implemented__')
+    def __init__(self, *args, **kw):
+        self.__implemented__ = interface.implementedBy(
+            self.__call__.im_func)
+        self.__component_adapts__ = component.adaptedBy(
+            self.__call__.im_func)
+        super(Declarer, self).__init__(*args, **kw)
 
-        return component.adaptedBy(instance.__call__)
+    def __call__(self):
+        return self
 
-class Declarer(object):
-
-    __implemented__ = ImplementsDescriptor()
-    __component_adapts__ = AdaptsDescriptor()
+implemented = interface.implementedBy(Declarer)
+Declarer.__implemented__ = ImplementsDescriptor(*implemented)

Modified: z3c.persistentfactory/trunk/z3c/persistentfactory/declarations.txt
===================================================================
--- z3c.persistentfactory/trunk/z3c/persistentfactory/declarations.txt	2008-04-10 19:08:46 UTC (rev 85220)
+++ z3c.persistentfactory/trunk/z3c/persistentfactory/declarations.txt	2008-04-10 20:04:52 UTC (rev 85221)
@@ -71,3 +71,21 @@
     (<InterfaceClass z3c.persistentfactory.testing.IFoo>,)
     >>> component.adaptedBy(bar_unpickled)
     (<InterfaceClass z3c.persistentfactory.testing.IBar>,)
+
+The declarations of the class are isolated from the declarations on an
+instance.
+    
+    >>> tuple(interface.implementedBy(declarations.Declarer))
+    ()
+    >>> component.adaptedBy(declarations.Declarer)
+
+Classes the use Declarer as a base class can have declarations.
+
+    >>> class Qux(declarations.Declarer):
+    ...     interface.implements(testing.IQux)
+    ...     component.adapts(testing.IBaz)
+
+    >>> tuple(interface.implementedBy(Qux))
+    (<InterfaceClass z3c.persistentfactory.testing.IQux>,)
+    >>> component.adaptedBy(Qux)
+    (<InterfaceClass z3c.persistentfactory.testing.IBaz>,)

Modified: z3c.persistentfactory/trunk/z3c/persistentfactory/factory.py
===================================================================
--- z3c.persistentfactory/trunk/z3c/persistentfactory/factory.py	2008-04-10 19:08:46 UTC (rev 85220)
+++ z3c.persistentfactory/trunk/z3c/persistentfactory/factory.py	2008-04-10 20:04:52 UTC (rev 85221)
@@ -10,7 +10,7 @@
     def __init__(self, method):
         self.context = method.im_self
         self.__name__ = method.__name__
-        self.__implemented__ = interface.implementedBy(method)
+        super(PersistentFactory, self).__init__()
 
     @property
     def __call__(self):

Modified: z3c.persistentfactory/trunk/z3c/persistentfactory/factory.txt
===================================================================
--- z3c.persistentfactory/trunk/z3c/persistentfactory/factory.txt	2008-04-10 19:08:46 UTC (rev 85220)
+++ z3c.persistentfactory/trunk/z3c/persistentfactory/factory.txt	2008-04-10 20:04:52 UTC (rev 85221)
@@ -65,15 +65,11 @@
     >>> component.adaptedBy(bar_factory)
     (<InterfaceClass z3c.persistentfactory.testing.IFoo>,)
 
-If the wrapped method's declarations haven't been overridden, then
-changes to the wrapped method's adapts declarations are reflected in
-the factory.  Unfortunately, the zope.interface implementation for
-checking implementer declarations checks the factory's instance
-dictionary directly, so changes to the wrapped method's implements
-declarations aren't reflected in the factory.  This means that any
-changes to the wrapped methods implements declaration that need to be
-reflected in existing persistent factories will require migrating the
-existing factories.
+Changes to the wrapped method's declarations are not reflected in the
+factory's declarations even if the wrapped method's declarations
+haven't been overridden.  This means that any changes to the wrapped
+methods implements declaration that need to be reflected in existing
+persistent factories will require migrating the existing factories.
 
     >>> _ = interface.implementer(testing.IFoo)(bar.factory.im_func)
     >>> _ = component.adapter(testing.IBar)(bar.factory.im_func)
@@ -86,7 +82,7 @@
     >>> tuple(interface.implementedBy(bar_factory))
     (<InterfaceClass z3c.persistentfactory.testing.IBar>,)
     >>> component.adaptedBy(bar_factory)
-    (<InterfaceClass z3c.persistentfactory.testing.IBar>,)
+    (<InterfaceClass z3c.persistentfactory.testing.IFoo>,)
 
 The wrapped method's declarations can be overridden in the factory.
 



More information about the Checkins mailing list