[Zope-Checkins]
SVN: Zope/branches/jim-fix-zclasses/lib/python/ExtensionClass/
Fixed bug in Base __getattro__ that caused __of__ to be missed in
Jim Fulton
jim at zope.com
Sun Feb 13 11:15:15 EST 2005
Log message for revision 29135:
Fixed bug in Base __getattro__ that caused __of__ to be missed in
instances of instances of subclasses (meta classes) of ExtensionClass.
Changed:
U Zope/branches/jim-fix-zclasses/lib/python/ExtensionClass/_ExtensionClass.c
U Zope/branches/jim-fix-zclasses/lib/python/ExtensionClass/tests.py
-=-
Modified: Zope/branches/jim-fix-zclasses/lib/python/ExtensionClass/_ExtensionClass.c
===================================================================
--- Zope/branches/jim-fix-zclasses/lib/python/ExtensionClass/_ExtensionClass.c 2005-02-13 16:04:04 UTC (rev 29134)
+++ Zope/branches/jim-fix-zclasses/lib/python/ExtensionClass/_ExtensionClass.c 2005-02-13 16:15:15 UTC (rev 29135)
@@ -142,7 +142,8 @@
If the tp_descr_get of res is of_get,
then call it. */
- if (res->ob_type->ob_type == &ExtensionClassType
+ if (PyObject_TypeCheck(res->ob_type,
+ &ExtensionClassType)
&& res->ob_type->tp_descr_get != NULL)
res = res->ob_type->tp_descr_get(
res, obj,
Modified: Zope/branches/jim-fix-zclasses/lib/python/ExtensionClass/tests.py
===================================================================
--- Zope/branches/jim-fix-zclasses/lib/python/ExtensionClass/tests.py 2005-02-13 16:04:04 UTC (rev 29134)
+++ Zope/branches/jim-fix-zclasses/lib/python/ExtensionClass/tests.py 2005-02-13 16:15:15 UTC (rev 29135)
@@ -709,6 +709,34 @@
"""
+def test___of___w_metaclass_instance():
+ """When looking for extension class instances, need to handle meta classes
+
+ >>> class C(Base):
+ ... pass
+
+ >>> class O(Base):
+ ... def __of__(self, parent):
+ ... print '__of__ called on an O'
+
+ >>> class M(ExtensionClass):
+ ... pass
+
+ >>> class X:
+ ... __metaclass__ = M
+ ...
+
+ >>> class S(X, O):
+ ... pass
+
+ >>> c = C()
+ >>> c.s = S()
+ >>> c.s
+ __of__ called on an O
+
+ """
+
+
from doctest import DocTestSuite
import unittest
More information about the Zope-Checkins
mailing list