[Checkins] SVN: zope.interface/branches/regebro-python3/src/zope/interface/ Changing the syntax for separating classes and other objects back to how it was in 3.5.x, so that you can use implementer on instances. zope.formlib soes this.

Lennart Regebro regebro at gmail.com
Sat Dec 5 04:41:24 EST 2009


Log message for revision 106214:
  Changing the syntax for separating classes and other objects back to how it was in 3.5.x, so that you can use implementer on instances. zope.formlib soes this.
  

Changed:
  U   zope.interface/branches/regebro-python3/src/zope/interface/README.txt
  U   zope.interface/branches/regebro-python3/src/zope/interface/declarations.py

-=-
Modified: zope.interface/branches/regebro-python3/src/zope/interface/README.txt
===================================================================
--- zope.interface/branches/regebro-python3/src/zope/interface/README.txt	2009-12-05 08:58:40 UTC (rev 106213)
+++ zope.interface/branches/regebro-python3/src/zope/interface/README.txt	2009-12-05 09:41:23 UTC (rev 106214)
@@ -231,10 +231,24 @@
 Note that the implementer decorator may modify it's argument. Callers
 should not assume that a new object is created.
 
+Using implementer also works on callable objects. This is used by
+zope.formlib, as an example.
+
+  >>> class yfactory:
+  ...     def __call__(self, y):
+  ...         foo = Foo()
+  ...         foo.y = y
+  ...         return foo
+  >>> yfoo = yfactory()
+  >>> yfoo = zope.interface.implementer(IFoo)(yfoo)
+
+  >>> list(zope.interface.implementedBy(yfoo))
+  [<InterfaceClass __main__.IFoo>]
+
 XXX: Double check and update these version numbers:
 
-In zope.interface 3.5.1 and lower, the implementor decorator can not
-be used for classes, but in 3.5.2 and higher it can:
+In zope.interface 3.5.2 and lower, the implementor decorator can not
+be used for classes, but in 3.6.0 and higher it can:
 
   >>> Foo = zope.interface.implementer(IFoo)(Foo)
   >>> list(zope.interface.providedBy(Foo()))

Modified: zope.interface/branches/regebro-python3/src/zope/interface/declarations.py
===================================================================
--- zope.interface/branches/regebro-python3/src/zope/interface/declarations.py	2009-12-05 08:58:40 UTC (rev 106213)
+++ zope.interface/branches/regebro-python3/src/zope/interface/declarations.py	2009-12-05 09:41:23 UTC (rev 106214)
@@ -457,11 +457,20 @@
 
     if spec.inherit is not None:
 
-        for c in spec.inherit.__bases__:
-            b = implementedBy(c)
-            if b not in seen:
-                seen[b] = 1
-                bases.append(b)
+        try:
+            for c in spec.inherit.__bases__:
+                b = implementedBy(c)
+                if b not in seen:
+                    seen[b] = 1
+                    bases.append(b)
+        except:
+            import pdb;pdb.set_trace()
+            for c in spec.inherit.__bases__:
+                b = implementedBy(c)
+                if b not in seen:
+                    seen[b] = 1
+                    bases.append(b)
+            
 
     spec.__bases__ = tuple(bases)
 
@@ -478,17 +487,27 @@
         self.interfaces = interfaces
 
     def __call__(self, ob):
-        if isinstance(ob, (FunctionType, MethodType)):
-            spec = Implements(*self.interfaces)
-            try:
-                ob.__implemented__ = spec
-            except AttributeError:
-                raise TypeError("Can't declare implements", ob)
-            return ob
-        else:
-            # Assume it's a class:
+        if isinstance(ob, DescriptorAwareMetaClasses):
             classImplements(ob, *self.interfaces)
             return ob            
+        
+        spec = Implements(*self.interfaces)
+        try:
+            ob.__implemented__ = spec
+        except AttributeError:
+            raise TypeError("Can't declare implements", ob)
+        return ob
+        #if isinstance(ob, (FunctionType, MethodType)):
+            #spec = Implements(*self.interfaces)
+            #try:
+                #ob.__implemented__ = spec
+            #except AttributeError:
+                #raise TypeError("Can't declare implements", ob)
+            #return ob
+        #else:
+            ## Assume it's a class:
+            #classImplements(ob, *self.interfaces)
+            #return ob            
 
 class implementer_only:
 



More information about the checkins mailing list