[Zope3-checkins] SVN: Zope3/branches/ZopeX3-3.0/src/zope/interface/ Merged from trunk:

Jim Fulton jim at zope.com
Wed Aug 11 14:37:32 EDT 2004


Log message for revision 27018:
  Merged from trunk:
  
    r26986 | jim | 2004-08-10 19:19:04 -0400 (Tue, 10 Aug 2004) | 5 lines
  
  Added an __sro__ attribute
  
  Also wrote some docs/tests for methods on declarations that are also
  avaialble for interfaces.
  


Changed:
  U   Zope3/branches/ZopeX3-3.0/src/zope/interface/README.txt
  U   Zope3/branches/ZopeX3-3.0/src/zope/interface/interface.py
  U   Zope3/branches/ZopeX3-3.0/src/zope/interface/interfaces.py


-=-
Modified: Zope3/branches/ZopeX3-3.0/src/zope/interface/README.txt
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/interface/README.txt	2004-08-11 18:36:43 UTC (rev 27017)
+++ Zope3/branches/ZopeX3-3.0/src/zope/interface/README.txt	2004-08-11 18:37:32 UTC (rev 27018)
@@ -4,6 +4,11 @@
 
 .. contents::
 
+.. Doctest directive that causes whitespace to be normalized when
+   comparing expected and actual output. This allows us to wrap long
+   lines out output:
+   >>> doctest: +NORMALIZE_WHITESPACE
+
 Interfaces are objects that specify (document) the external behavior
 of objects that "provide" them.  An interface specifies behavior
 through: 
@@ -389,8 +394,6 @@
   [<InterfaceClass __main__.IFoo>, <InterfaceClass __main__.ISpecial>]
 
 
-
-
 Interface Inheritance
 =====================
 
@@ -462,6 +465,40 @@
   ['eek']
 
 
+Specifications
+--------------
+
+Interfaces and declarations are both special cases of specifications.
+What we described above for interface inheritence applies to both
+declarations and specifications.  Declarations actually extend the
+interfaces that they declare:
+
+  >>> class Baz:
+  ...     zope.interface.implements(IBaz)
+
+  >>> baz_implements = zope.interface.implementedBy(Baz)
+  >>> baz_implements.__bases__
+  (<InterfaceClass __main__.IBaz>,)
+
+  >>> baz_implements.extends(IFoo)
+  True
+
+  >>> baz_implements.isOrExtends(IFoo)
+  True
+  >>> baz_implements.isOrExtends(baz_implements)
+  True
+
+Specifications (interfaces and declarations) provide an `__sro__`
+that lists the specification and all of it's ancestors:
+
+  >>> baz_implements.__sro__
+  (<implementedBy __main__.Baz>, 
+   <InterfaceClass __main__.IBaz>, 
+   <InterfaceClass __main__.IFoo>, 
+   <InterfaceClass __main__.IBlat>, 
+   <InterfaceClass zope.interface.Interface>)
+
+
 Tagged Values
 =============
 

Modified: Zope3/branches/ZopeX3-3.0/src/zope/interface/interface.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/interface/interface.py	2004-08-11 18:36:43 UTC (rev 27017)
+++ Zope3/branches/ZopeX3-3.0/src/zope/interface/interface.py	2004-08-11 18:37:32 UTC (rev 27018)
@@ -257,6 +257,7 @@
         implied.clear()
 
         ancestors = ro(self)
+        self.__sro__ = tuple(ancestors)
         self.__iro__ = tuple([ancestor for ancestor in ancestors
                               if isinstance(ancestor, InterfaceClass)
                              ])

Modified: Zope3/branches/ZopeX3-3.0/src/zope/interface/interfaces.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/interface/interfaces.py	2004-08-11 18:36:43 UTC (rev 27017)
+++ Zope3/branches/ZopeX3-3.0/src/zope/interface/interfaces.py	2004-08-11 18:37:32 UTC (rev 27018)
@@ -93,7 +93,14 @@
 
     """)
 
+    __sro__ = Attribute("""Specification-resolution order
 
+    A tuple of the specification and all of it's ancestor
+    specifications from most specific to least specific.
+
+    (This is similar to the method-resolution order for new-style classes.)
+    """)
+
     def get(name, default=None):
         """Look up the description for a name
 



More information about the Zope3-Checkins mailing list