Description
A less horribly slow method would be to pre-compile the Python source code, not re-evaluating it from a string every time. Or to expand the Python code into a series of PyXxx() function calls, with something along the lines of PyObject_CallMethod(sys_module, "_getframe", PyLong_FromLong(1))
and some PyObject_GetAttrString()
on the result.
I imagine you already know it, but the kind of check done here (for both CPython or PyPy) is quite hackish. I would guess the problem is that when the user writes BaseClassInCpp.method(self)
it really invokes the derived method, which makes an infinite loop in the case of overloaded methods in Python that wants to call the parent implementation. It would be an API change, but couldn't BaseClassInCpp.method(self)
always invoke the base class method (or the closest written in C++), which might be different from self.method()
?
Originally posted by @arigo in #2436 (comment)