[Checkins] SVN: zope.interface/branches/tseaver-no_2to3/src/zope/interface/declarations.py Improve the error raised by the class advice APIs when invoked under Py3k.

Tres Seaver cvs-admin at zope.org
Fri Apr 6 05:35:32 UTC 2012


Log message for revision 124989:
  Improve the error raised by the class advice APIs when invoked under Py3k.

Changed:
  U   zope.interface/branches/tseaver-no_2to3/src/zope/interface/declarations.py

-=-
Modified: zope.interface/branches/tseaver-no_2to3/src/zope/interface/declarations.py
===================================================================
--- zope.interface/branches/tseaver-no_2to3/src/zope/interface/declarations.py	2012-04-06 04:14:37 UTC (rev 124988)
+++ zope.interface/branches/tseaver-no_2to3/src/zope/interface/declarations.py	2012-04-06 05:35:28 UTC (rev 124989)
@@ -37,6 +37,7 @@
 from zope.interface.interface import SpecificationBase
 from zope.interface.interface import Specification
 from zope.interface._compat import CLASS_TYPES as DescriptorAwareMetaClasses
+from zope.interface._compat import PYTHON3
 
 # Registry of class-implementation specifications
 BuiltinImplementationSpecifications = {}
@@ -347,7 +348,7 @@
 def _implements(name, interfaces, classImplements):
     # This entire approach is invalid under Py3K.  Don't even try to fix
     # the coverage for this block there. :(
-    if sys.version_info[0] >= 3: #pragma NO COVER
+    if PYTHON3: #pragma NO COVER
         raise TypeError('Class advice impossible in Python3')
     frame = sys._getframe(2)
     locals = frame.f_locals
@@ -392,6 +393,10 @@
     """
     # This entire approach is invalid under Py3K.  Don't even try to fix
     # the coverage for this block there. :(
+    if PYTHON3: #pragma NO COVER
+        raise TypeError('Class advice impossible in Python3.  Use the'
+                        '@implementer class decorator instead.'
+                       )
     _implements("implements", interfaces, classImplements)
 
 def implementsOnly(*interfaces):
@@ -418,6 +423,10 @@
     """
     # This entire approach is invalid under Py3K.  Don't even try to fix
     # the coverage for this block there. :(
+    if PYTHON3: #pragma NO COVER
+        raise TypeError('Class advice impossible in Python3.  Use the'
+                        '@implementer_only class decorator instead.'
+                       )
     _implements("implementsOnly", interfaces, classImplementsOnly)
 
 ##############################################################################
@@ -621,8 +630,10 @@
     """
     # This entire approach is invalid under Py3K.  Don't even try to fix
     # the coverage for this block there. :(
-    if sys.version_info[0] >= 3: #pragma NO COVER
-        raise TypeError('Class advice impossible in Python3')
+    if PYTHON3: #pragma NO COVER
+        raise TypeError('Class advice impossible in Python3.  Use the'
+                        '@provider class decorator instead.'
+                       )
 
     frame = sys._getframe(1)
     locals = frame.f_locals



More information about the checkins mailing list