[PEAK] Dispatch on isinstance() for Zope Extension classes

Phillip J. Eby pje at telecommunity.com
Wed Mar 29 12:15:46 EST 2006


At 06:07 PM 3/29/2006 +0200, Alain Poirier wrote:
>Here is where I'am for the moment. Any ideas ?

Try this patch for dispatch._speedups.

I thought the other problem might be that protocols.advice.getMRO (and 
protocols._speedups.getMRO) don't support ExtensionClass.  But I looked at 
those and they have code that tries to import ExtensionClass and then tries 
to handle it accordingly.  You might try importing 
protocols.advice.ClassTypes and see if ExtensionClass is in there.  Or 
better yet, try protocols.advice.getMRO(SomeExtClass) and see if it gives 
you something meaningful.


Index: src/dispatch/_speedups.pyx
===================================================================
--- src/dispatch/_speedups.pyx  (revision 2115)
+++ src/dispatch/_speedups.pyx  (working copy)
@@ -7,6 +7,7 @@
  from dispatch.interfaces import NoApplicableMethods, DispatchError
  from types import InstanceType
  __nclass = "__class__"
+__nbases = "__bases__"

  _NF = [0,None, NoApplicableMethods, (None,None)]

@@ -38,7 +39,6 @@



-
  cdef extern from "Python.h":
      int PyType_Check(object ob)
      int PyClass_Check(object ob)
@@ -231,12 +231,20 @@
          tmp = PyDict_GetItem(table, klass)
          if tmp:
              return <object>tmp
-
          if PyClass_Check(klass):
              bases = (<PyClassObject *>klass).cl_bases
          elif PyType_Check(klass):
              bases = (<PyTypeObject *>klass).tp_bases
          else:
+            bases = NULL
+            tmp = PyObject_GetAttr(ob, __nbases)
+            if tmp:
+                bt = <object> tmp
+                if PyTuple_Check(bt):
+                    bases = <PyTupleObject *> tmp
+                bt = None
+
+        if not bases:
              raise TypeError("Not a class or type:", klass)

          bc = PyTuple_GET_SIZE(bases)




More information about the PEAK mailing list