Index: boost/python/object/function.hpp =================================================================== --- boost/python/object/function.hpp (revision 65433) +++ boost/python/object/function.hpp (working copy) @@ -39,6 +39,8 @@ void doc(object const& x); object const& name() const; + + object const& get_namespace() const { return m_namespace; } private: // helper functions object signature(bool show_return_type=false) const; Index: libs/python/src/object/function.cpp =================================================================== --- libs/python/src/object/function.cpp (revision 65433) +++ libs/python/src/object/function.cpp (working copy) @@ -670,11 +670,26 @@ { return python::incref(upcast(&PyCFunction_Type)); } + + static PyObject* function_get_module(PyObject* op, void*) + { + function* f = downcast(op); + object const& ns = f->get_namespace(); + if (!ns.is_none()) { + return python::incref(ns.ptr()); + } + PyErr_SetString( + PyExc_AttributeError, const_cast( + "Boost.Python function __module__ unknown.")); + return 0; + } } static PyGetSetDef function_getsetlist[] = { {const_cast("__name__"), (getter)function_get_name, 0, 0, 0 }, {const_cast("func_name"), (getter)function_get_name, 0, 0, 0 }, + {const_cast("__module__"), (getter)function_get_module, 0, 0, 0 }, + {const_cast("func_module"), (getter)function_get_module, 0, 0, 0 }, {const_cast("__class__"), (getter)function_get_class, 0, 0, 0 }, // see note above {const_cast("__doc__"), (getter)function_get_doc, (setter)function_set_doc, 0, 0}, {const_cast("func_doc"), (getter)function_get_doc, (setter)function_set_doc, 0, 0},