diff --git a/src/App/ExtensionContainerPyImp.cpp b/src/App/ExtensionContainerPyImp.cpp index 9296cbdc71..07c342799e 100644 --- a/src/App/ExtensionContainerPyImp.cpp +++ b/src/App/ExtensionContainerPyImp.cpp @@ -112,6 +112,30 @@ int ExtensionContainerPy::PyInit(PyObject* /*args*/, PyObject* /*kwd*/) PyObject *ExtensionContainerPy::getCustomAttributes(const char* attr) const { + if (Base::streq(attr, "__dict__")) { + PyObject* dict = PyDict_New(); + PyObject* props = PropertyContainerPy::getCustomAttributes("__dict__"); + if (props && PyDict_Check(props)) { + PyDict_Merge(dict, props, 0); + Py_DECREF(props); + } + + ExtensionContainer::ExtensionIterator it = this->getExtensionContainerPtr()->extensionBegin(); + for (; it != this->getExtensionContainerPtr()->extensionEnd(); ++it) { + // The PyTypeObject is shared by all instances of this type and therefore + // we have to add new methods only once. + PyObject* obj = (*it).second->getExtensionPyObject(); + PyTypeObject *tp = Py_TYPE(obj); + if (tp && tp->tp_dict) { + Py_XINCREF(tp->tp_dict); + PyDict_Merge(dict, tp->tp_dict, 0); + Py_XDECREF(tp->tp_dict); + } + Py_DECREF(obj); + } + + return dict; + } // Search for the method called 'attr' in the extensions. If the search with // Py_FindMethod is successful then a PyCFunction_New instance is returned // with the PyObject pointer of the extension to make sure the method will