In wxPython the code I use for reflecting virtual C++ method calls to Python
methods checks first that the method is implemented in a derived class
otherwise it just calls the C++ base class version. Here is a bit of the
code:
PyObject* method;
method = PyObject_GetAttrString(m_self, (char*)name);
if (PyMethod_Check(method) &&
((PyMethod_GET_CLASS(method) == m_class) ||
PyClass_IsSubclass(PyMethod_GET_CLASS(method), m_class))) {
This worked fine prior to Python 2.2 (the earliest I tried was 2.2b1) and
the PyMethod_GET_CLASS macro would give me the actual class that the method
was defined in. Unfortunatly in 2.2 it appears that the class object
returned is now the class of m_self which in my test case is the derived
class which does not define the method. This issue is further illustrated
by the following Python code:
class A:
def spam(self):
print "spam"
class B(A):
pass
import sys
print sys.version
b = B()
print b.spam
Which, when run with Python 2.1.1 and Python 2.2b2 gives this output:
storm:robind> p21 /tmp/method.py
2.1.1 (#1, Aug 30 2001, 17:36:05)
[GCC 2.96 20000731 (Mandrake Linux 8.1 2.96-0.61mdk)]
participants (1)
-
Robin Dunn