[Zope3-checkins] SVN: Zope3/trunk/src/zope/interface/ Fixed a bug in getting implements spec for proxied built-in objects.

Jim Fulton jim at zope.com
Tue Aug 10 15:49:07 EDT 2004


Log message for revision 26975:
  Fixed a bug in getting implements spec for proxied built-in objects.
  


Changed:
  U   Zope3/trunk/src/zope/interface/declarations.py
  U   Zope3/trunk/src/zope/interface/tests/test_declarations.py


-=-
Modified: Zope3/trunk/src/zope/interface/declarations.py
===================================================================
--- Zope3/trunk/src/zope/interface/declarations.py	2004-08-10 19:48:17 UTC (rev 26974)
+++ Zope3/trunk/src/zope/interface/declarations.py	2004-08-10 19:49:07 UTC (rev 26975)
@@ -376,7 +376,12 @@
 
         spec = getattr(cls, '__implemented__', None)
         if spec is None:
+            # There's no spec stred in the class. Maybe its a builtin:
+            spec = BuiltinImplementationSpecifications.get(cls)
+            if spec is not None:
+                return spec
             return _empty
+        
         if spec.__class__ == Implements:
             # we defaulted to _empty or there was a spec. Good enough.
             # Return it.

Modified: Zope3/trunk/src/zope/interface/tests/test_declarations.py
===================================================================
--- Zope3/trunk/src/zope/interface/tests/test_declarations.py	2004-08-10 19:48:17 UTC (rev 26974)
+++ Zope3/trunk/src/zope/interface/tests/test_declarations.py	2004-08-10 19:49:07 UTC (rev 26975)
@@ -278,6 +278,39 @@
           ['IFoo']
     """
 
+def test_getting_spec_for_proxied_builtin_class():
+    """
+
+    In general, we should be able to get a spec
+    for a proxied class if someone has declared or
+    asked for a spec before.
+
+    We don't want to depend on proxies in this (zope.interface)
+    package, but we do want to work with proxies.  Proxies have the
+    effect that a class's __dict__ cannot be gotten. Further, for
+    built-in classes, we can't save, and thus, cannot get, any class
+    attributes.  We'll emulate this by treating a plain object as a class:
+
+      >>> cls = object()
+
+    We'll create an implements specification:
+
+      >>> import zope.interface.declarations
+      >>> impl = zope.interface.declarations.Implements(I1, I2)
+
+    Now, we'll emulate a declaration for a built-in type by putting
+    it in BuiltinImplementationSpecifications:
+
+      >>> zope.interface.declarations.BuiltinImplementationSpecifications[
+      ...   cls] = impl
+
+    Now, we should be able to get it back:
+
+      >>> implementedBy(cls) is impl
+      True
+    
+    """
+
 def test_suite():
     suite = unittest.TestSuite()
     suite.addTest(unittest.makeSuite(Test))



More information about the Zope3-Checkins mailing list