[Checkins] SVN: zope.interface/branches/regebro-python3/src/zope/interface/ Fixed enough bugs to make tests run, but fail.

Lennart Regebro regebro at gmail.com
Tue Mar 31 15:21:56 EDT 2009


Log message for revision 98721:
  Fixed enough bugs to make tests run, but fail.
  
  Changed implementor to also support classes.
  

Changed:
  U   zope.interface/branches/regebro-python3/src/zope/interface/README.ru.txt
  U   zope.interface/branches/regebro-python3/src/zope/interface/README.txt
  U   zope.interface/branches/regebro-python3/src/zope/interface/advice.py
  U   zope.interface/branches/regebro-python3/src/zope/interface/declarations.py
  U   zope.interface/branches/regebro-python3/src/zope/interface/interface.py
  U   zope.interface/branches/regebro-python3/src/zope/interface/tests/__init__.py
  U   zope.interface/branches/regebro-python3/src/zope/interface/tests/test_advice.py
  U   zope.interface/branches/regebro-python3/src/zope/interface/tests/test_odd_declarations.py

-=-
Modified: zope.interface/branches/regebro-python3/src/zope/interface/README.ru.txt
===================================================================
--- zope.interface/branches/regebro-python3/src/zope/interface/README.ru.txt	2009-03-31 19:16:02 UTC (rev 98720)
+++ zope.interface/branches/regebro-python3/src/zope/interface/README.ru.txt	2009-03-31 19:21:56 UTC (rev 98721)
@@ -231,16 +231,19 @@
 Вызывающая сторона не должна предполагать, что всегда будет создаваться
 новый объект.
 
-Также надо отметить, что как минимум сейчас implementer не может использоваться
-для классов::
+XXX: Double check and update these version numbers, and translate to russian:
 
-  >>> zope.interface.implementer(IFoo)(Foo)
-  ... # doctest: +NORMALIZE_WHITESPACE
-  Traceback (most recent call last):
-    ...
-  TypeError: Can't use implementer with classes.
-  Use one of the class-declaration functions instead.
+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:
 
+  >>> Foo = zope.interface.implementer(IFoo)(Foo)
+  >>> list(zope.interface.providedBy(Foo()))
+  [<InterfaceClass __main__.IFoo>]
+  
+Note that class decorators using the @implementor(IFoo) syntax are only 
+supported in Python 2.6 and later.
+
+
 Объявление предоставляемых интерфейсов
 --------------------------------------
 

Modified: zope.interface/branches/regebro-python3/src/zope/interface/README.txt
===================================================================
--- zope.interface/branches/regebro-python3/src/zope/interface/README.txt	2009-03-31 19:16:02 UTC (rev 98720)
+++ zope.interface/branches/regebro-python3/src/zope/interface/README.txt	2009-03-31 19:21:56 UTC (rev 98721)
@@ -231,16 +231,19 @@
 Note that the implementer decorator may modify it's argument. Callers
 should not assume that a new object is created.
 
-Also note that, at least for now, implementer can't be used with
-classes::
+XXX: Double check and update these version numbers:
 
-  >>> zope.interface.implementer(IFoo)(Foo)
-  ... # doctest: +NORMALIZE_WHITESPACE
-  Traceback (most recent call last):
-    ...
-  TypeError: Can't use implementer with classes.
-  Use one of the class-declaration functions instead.
+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:
 
+  >>> Foo = zope.interface.implementer(IFoo)(Foo)
+  >>> list(zope.interface.providedBy(Foo()))
+  [<InterfaceClass __main__.IFoo>]
+  
+Note that class decorators using the @implementor(IFoo) syntax are only 
+supported in Python 2.6 and later.
+
+
 Declaring provided interfaces
 -----------------------------
 

Modified: zope.interface/branches/regebro-python3/src/zope/interface/advice.py
===================================================================
--- zope.interface/branches/regebro-python3/src/zope/interface/advice.py	2009-03-31 19:16:02 UTC (rev 98720)
+++ zope.interface/branches/regebro-python3/src/zope/interface/advice.py	2009-03-31 19:21:56 UTC (rev 98721)
@@ -109,6 +109,7 @@
 
     previousMetaclass = caller_locals.get('__metaclass__')
     if __python3:
+        # XXX This is probably not gonna work.
         defaultMetaclass  = caller_globals.get('__metaclass__', type)
     else:
         defaultMetaclass  = caller_globals.get('__metaclass__', ClassType)

Modified: zope.interface/branches/regebro-python3/src/zope/interface/declarations.py
===================================================================
--- zope.interface/branches/regebro-python3/src/zope/interface/declarations.py	2009-03-31 19:16:02 UTC (rev 98720)
+++ zope.interface/branches/regebro-python3/src/zope/interface/declarations.py	2009-03-31 19:21:56 UTC (rev 98721)
@@ -492,9 +492,9 @@
 
     def __call__(self, ob):
         if isinstance(ob, DescriptorAwareMetaClasses):
-            raise TypeError("Can't use implementer with classes.  Use one of "
-                            "the class-declaration functions instead."
-                            )
+            # XXX Here I am!
+            classImplements(ob, *self.interfaces)
+            return ob
         spec = Implements(*self.interfaces)
         try:
             ob.__implemented__ = spec

Modified: zope.interface/branches/regebro-python3/src/zope/interface/interface.py
===================================================================
--- zope.interface/branches/regebro-python3/src/zope/interface/interface.py	2009-03-31 19:16:02 UTC (rev 98720)
+++ zope.interface/branches/regebro-python3/src/zope/interface/interface.py	2009-03-31 19:21:56 UTC (rev 98721)
@@ -476,6 +476,9 @@
         # Make sure that all recorded attributes (and methods) are of type
         # `Attribute` and `Method`
         for name, attr in attrs.items():
+            if name == '__locals__':
+                # This happens under Python 3 sometimes
+                continue
             if isinstance(attr, Attribute):
                 attr.interface = self
                 if not attr.__name__:
@@ -570,7 +573,7 @@
         exec "class %s: pass" % self.__name__ in klass
         klass=klass[self.__name__]
 
-        self.__d(klass.__dict__)
+        self.__d(klass)
 
         self._deferred=klass
 
@@ -599,14 +602,13 @@
         """Retrieve a named interface."""
         return None
 
-    def __d(self, dict):
-
+    def __d(self, klass):
         for k, v in self.__attrs.items():
-            if isinstance(v, Method) and not (k in dict):
-                dict[k]=v
+            if isinstance(v, Method) and not (k in klass.__dict__):
+                setattr(klass, k, v)
 
         for b in self.__bases__:
-            b.__d(dict)
+            b.__d(klass)
 
     def __repr__(self):
         try:

Modified: zope.interface/branches/regebro-python3/src/zope/interface/tests/__init__.py
===================================================================
--- zope.interface/branches/regebro-python3/src/zope/interface/tests/__init__.py	2009-03-31 19:16:02 UTC (rev 98720)
+++ zope.interface/branches/regebro-python3/src/zope/interface/tests/__init__.py	2009-03-31 19:21:56 UTC (rev 98721)
@@ -8,7 +8,8 @@
     for file in os.listdir(os.path.dirname(__file__)):
         if file.endswith('.py') and file!='__init__.py':
             name = os.path.splitext(file)[0]
-            module = __import__('.'.join((__name__, name)), fromlist=name)
+            module = __import__('.'.join((__name__, name)), globals(), 
+                                locals(), [name])
             if hasattr(module, 'test_suite'):
                 suites.addTests(module.test_suite())
     return suites

Modified: zope.interface/branches/regebro-python3/src/zope/interface/tests/test_advice.py
===================================================================
--- zope.interface/branches/regebro-python3/src/zope/interface/tests/test_advice.py	2009-03-31 19:16:02 UTC (rev 98720)
+++ zope.interface/branches/regebro-python3/src/zope/interface/tests/test_advice.py	2009-03-31 19:21:56 UTC (rev 98721)
@@ -31,7 +31,6 @@
 import unittest
 from unittest import TestCase, makeSuite, TestSuite
 from zope.interface.advice import *
-from types import ClassType
 import sys
 
 def ping(log, value):
@@ -42,9 +41,14 @@
 
     addClassAdvisor(pong)
 
-class ClassicClass:
-    __metaclass__ = ClassType
-    classLevelFrameInfo = getFrameInfo(sys._getframe())
+try:
+    from types import ClassType
+    
+    class ClassicClass:
+        __metaclass__ = ClassType
+        classLevelFrameInfo = getFrameInfo(sys._getframe())
+except ImportError:
+    pass
 
 class NewStyleClass:
     __metaclass__ = type

Modified: zope.interface/branches/regebro-python3/src/zope/interface/tests/test_odd_declarations.py
===================================================================
--- zope.interface/branches/regebro-python3/src/zope/interface/tests/test_odd_declarations.py	2009-03-31 19:16:02 UTC (rev 98720)
+++ zope.interface/branches/regebro-python3/src/zope/interface/tests/test_odd_declarations.py	2009-03-31 19:21:56 UTC (rev 98721)
@@ -18,7 +18,8 @@
 
 $Id$
 """
-import unittest, odd
+import unittest
+from zope.interface.tests import odd
 from zope.interface import Interface, implements, implementsOnly
 from zope.interface import directlyProvides, providedBy, directlyProvidedBy
 from zope.interface import classImplements, classImplementsOnly, implementedBy



More information about the Checkins mailing list