[Zope-Checkins] CVS: Zope/lib/python/ExtensionClass - _ExtensionClass.c:1.1.2.7 tests.py:1.1.2.6

Jim Fulton cvs-admin at zope.org
Tue Nov 25 12:04:38 EST 2003


Update of /cvs-repository/Zope/lib/python/ExtensionClass
In directory cvs.zope.org:/tmp/cvs-serv14932/lib/python/ExtensionClass

Modified Files:
      Tag: zodb33-devel-branch
	_ExtensionClass.c tests.py 
Log Message:
Changed so __of__ is called only when an object with an __of__ method
is gotten from an extension class instance.


=== Zope/lib/python/ExtensionClass/_ExtensionClass.c 1.1.2.6 => 1.1.2.7 ===
--- Zope/lib/python/ExtensionClass/_ExtensionClass.c:1.1.2.6	Sat Nov 15 07:11:15 2003
+++ Zope/lib/python/ExtensionClass/_ExtensionClass.c	Tue Nov 25 12:04:37 2003
@@ -34,7 +34,7 @@
 of_get(PyObject *self, PyObject *inst, PyObject *cls)
 {
   /* Descriptor slot function that calls __of__ */
-  if (inst)
+  if (inst && PyExtensionInstance_Check(inst))
     return PyObject_CallMethodObjArgs(self, str__of__, inst, NULL);
 
   Py_INCREF(self);


=== Zope/lib/python/ExtensionClass/tests.py 1.1.2.5 => 1.1.2.6 ===
--- Zope/lib/python/ExtensionClass/tests.py:1.1.2.5	Sat Nov 15 07:11:15 2003
+++ Zope/lib/python/ExtensionClass/tests.py	Tue Nov 25 12:04:37 2003
@@ -638,6 +638,58 @@
     
     """
 
+def test_of_not_called_when_not_accessed_through_EC_instance():
+    """
+
+    >>> class Eek(Base):
+    ...     def __of__(self, parent):
+    ...         return self, parent
+
+    If I define an EC instance as an attr of an ordinary class:
+    
+    >>> class O(object):
+    ...     eek = Eek()
+    
+    >>> class C:
+    ...     eek = Eek()
+
+    I get the instance, without calling __of__, when I get it from
+    either tha class:
+
+    >>> O.eek is O.__dict__['eek']
+    True
+
+    >>> C.eek is C.__dict__['eek']
+    True
+
+    or an instance of the class:
+
+    >>> O().eek is O.__dict__['eek']
+    True
+
+    >>> C().eek is C.__dict__['eek']
+    True
+
+    If I define an EC instance as an attr of an extension class:
+    
+    >>> class E(Base):
+    ...     eek = Eek()
+    
+
+    I get the instance, without calling __of__, when I get it from
+    tha class:
+
+    >>> E.eek is E.__dict__['eek']
+    True
+
+    But __of__ is called if I go through the instance:
+
+    >>> e = E()
+    >>> e.eek == (E.__dict__['eek'], e)
+    True
+
+    """
+
 from doctest import DocTestSuite
 import unittest
 




More information about the Zope-Checkins mailing list